I have a python script that should turn off all layers in a ArcGIS Pro project. But when I run it, the following error pops up:
File "<string>", line 2, in <module>
IndexError: list index out of range
Here is the python code I am using.
p = arcpy.mp.ArcGISProject("Current")
m = p.listMaps("Name of map")[0]
lyrList = m.listLayers()
for lyr in lyrList:
lyr.visible = False
Anyone know what I am doing wrong or missing?
Solved! Go to Solution.
The simplest answer would be that the map "Name of map" doesn't exist in your project. I don't think you have to specify a map name, or you can use wildcards, if you don't always know the name.
The simplest answer would be that the map "Name of map" doesn't exist in your project. I don't think you have to specify a map name, or you can use wildcards, if you don't always know the name.
Thanks, using the wildcard worked. However, I didn't realize it would turn off the basemap also. Do you think I could fix that using an if/else statement?
You should be able to use the isBasemapLayer method - Layer—ArcPy | ArcGIS Desktop