Turn Layers off In ArcGIS Pro using Arcpy

2012
3
Jump to solution
11-20-2017 07:14 AM
Business_IntelligenceSoftware
Occasional Contributor

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?

Tags (2)
1 Solution

Accepted Solutions
PeteCrosier
Occasional Contributor III

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.

View solution in original post

3 Replies
PeteCrosier
Occasional Contributor III

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.

Business_IntelligenceSoftware
Occasional Contributor

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? 

0 Kudos
PeteCrosier
Occasional Contributor III

You should be able to use the isBasemapLayer method - Layer—ArcPy | ArcGIS Desktop