More

Setting Instance of MULTIPLE LAYERS using “mapLayersByName” in QGIS Python Scripting?

Setting Instance of MULTIPLE LAYERS using “mapLayersByName” in QGIS Python Scripting?


I'm currently using "mapLayersByName" successfully to set one active layer at a time as follows…

vl = QgsMapLayerRegistry.instance().mapLayersByName('My_Layer')[0] iface.setActiveLayer(vl)

Can an instance of multiple layers be set using the "mapLayersByName" method?

I have tried…

vl = QgsMapLayerRegistry.instance().mapLayersByName('My_First_Layer', 'My_Second_Layer')[0] iface.setActiveLayer(vl)

As you can see my end goal in this case would be to set the layers within that instance of MULTIPLE layers (vl) as the active layers using the "iface.setActiveLayer()" method. I notice this method is not plural (i.e. not "setActiveLayers()"). Significant?


No you can't.mapLayersByNamereturns a list of layers matching a single name (you can have many layers with the same name)

setActiveLayertakes a single active layer because there is only one active layer at a time in QGIS.


Watch the video: Aegis Solo kit with Cerberus Tank by Geekvape Ελληνική Παρουσίαση Greek review