Hi,
I have a map name (strings).
I want to know how to access the listLayer() of a specific map by the "string" name of the map.
x = "Map1"
for i in x.listLayers():
print("Layer: " + i.name)
not really working because I don't know how to "call" the specific map.
Thanks!
Maybe this example could help you:
https://pro.arcgis.com/de/pro-app/arcpy/mapping/layer-class.htm
import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
m = aprx.listMaps("Yosemite National Park")[0]
for lyr in m.listLayers():
if lyr.supports("DEFINITIONQUERY"):
lyr.definitionQuery = ""
if lyr.supports("SHOWLABELS"):
lyr.showLabels = False
aprx.save()
del aprx
Sorry @JohannesBierer ,I didn't notice your reply.
no problem, your solution is easier to follow 🙂
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
m = aprx.listMaps("Yosemite National Park")[0]
from the code sample on the layer class page Layer—ArcGIS Pro | Documentation
import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\myproject.aprx")
my_map = aprx.listMaps("Your Map")[0]
for lyr in my_map.listLayers():
print("Layer: " + lyr.name)