1

I'm a real beginner in Python. I'm using a Python script to produce maps automatically.

This script is working but it is failing in the last part: saving the current map with a specific print layout. Im using the "Maps Printer" Plugin to do this.

The code bellow worked in QGIS 2.18 but fail in Qgis 3.8.

# Your settings
composerTitle = 'Composer_001' # Name of the composer you want to export
folder = 'C:/Users/.../'
extension = '.jpeg' # Any extension supported by the plugin
titre = 'NomCarte'

mp = qgis.utils.plugins['MapsPrinter']

for composer in iface.activeComposers():
    title = composer.composerWindow().windowTitle()
    if title == composerTitle:
        mp.exportCompo( composer, folder, titre, extension )
        break

The command iface.activeComposers seems to not work anymore in QGIS 3.0. Does anyone have an idea to solve this problem?

1

You don't need loop active composer,only select print layout by name.

composerTitle = 'Composer_001' # Name of the composer you want to export

project = QgsProject.instance()
projectLayoutManager = project.layoutManager()
layout = projectLayoutManager.layoutByName(composerTitle)
1

Thank you so much Fran Raga, you solve my problem.

Here is the code to export a map by code using Maps Printer plugin :

from qgis.core import *
import qgis.utils

composerTitle = 'Composer_001' # Name of the composer you want to export
folder = 'C:/Users/.../'
extension = '.jpeg' # Any extension supp
title = 'TestExport'
project = QgsProject.instance()
projectLayoutManager = project.layoutManager()
layout = projectLayoutManager.layoutByName(composerTitle)

mp = qgis.utils.plugins['MapsPrinter']
mp.exportCompo(layout, folder, title, extension)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.