I have created 3 print layouts in QGIS3. Now I am trying to get a list of all layouts in the LayoutManager with python. This is how I am trying to do it(this code is executed in the python console of QGIS3):
>>> from qgis.core import QgsLayoutManager
>>> layoutmanager = QgsLayoutManager()
>>> layoutmanager.layouts()
>>> []
What I get is an empty list. So what am I missing? Do I have to save the Layouts in a special way? For those who don't understand what I mean with layout, in QGIS3 Layout is the new Composer.
Answer
With your code, you are creating a new instance of QgsLayoutManager. So, you don't get current list but an empty one.
You should retrieve the project instance with
projectInstance = QgsProject.instance()
From it, you can get the current layoutManager instance and deduce the layouts
projectLayoutManager = projectInstance.layoutManager()
projectLayoutManager.layouts()
If you are not aware of it, the new Python API docs really helped https://qgis.org/pyqgis/master/core/QgsProject.html
No comments:
Post a Comment