I have an open QGIS 3.0 project with a layout called "plan_view1". There are numerous selected layers (>100) that I want to turn on one-by-one and print the "plan_view1" layout to a pdf.
This is my code:
def printpdfmulti(layoutname):
selected_layers = qgis.utils.iface.layerTreeView().selectedLayers()
projectInstance = QgsProject.instance()
layoutmanager = projectInstance.layoutManager()
layout = layoutmanager.layoutByName(layoutname) #Layout nameprojectInstance = QgsProject.instance()
for layer in selected_layers:
qgis.utils.iface.legendInterface().setLayerVisible(layer, True)
exporter = QgsLayoutExporter(layout)
exporter.exportToPdf("C://data//" + layer.name() + ".pdf", QgsLayoutExporter.PdfExportSettings() )
qgis.utils.iface.legendInterface().setLayerVisible(layer, False)
printpdfmulti("plane_view1")
The error messsage I get is:
Traceback (most recent call last):
File "C:\OSGEO4~1\apps\Python36\lib\code.py", line 91, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "<string>", line 13, in <module>
File "<string>", line 7, in printpdfmulti
AttributeError: 'QgisInterface' object has no attribute 'legendInterface'
What have I done wrong? I know my python programming is still very rough on the edges.