How get layer by name in PyQGIS 3.0?
If you are sure there is one layer named LAYER_NAME
, the shortest way:
layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]
In that way, you can get a layer in a group layer.
print(layer)
# OUT: <qgis._core.QgsVectorLayer object at ...>
listLayers=QgsProject.instance().mapLayersByName('layername')
Retrieve a list of matching registered layers by layer name.