3

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.

TomazicM
  • 25,601
  • 22
  • 29
  • 39
Blinxen
  • 703
  • 5
  • 22

1 Answers1

5

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

Denis Rouzaud
  • 1,618
  • 11
  • 16
ThomasG77
  • 30,725
  • 1
  • 53
  • 93