I'm struggling to create a python script that will simply turn off all feature classes in the table of contents within my ArcGIS Pro project. I think part of my problem is the syntax change from ArcMap to Pro. I know that ESRI has a web page dedicated to that very issue (http://pro.arcgis.com/en/pro-app/arcpy/mapping/migratingfrom10xarcpymapping.htm), but the diagram on that page just seems to confuse me more.

Here is my attempt at creating a script to to turn off feature classes in ArcGIS Pro.

import arcpy
p = arcpy.mp.ArcGISProject("Current")
for lyrx in arcpy.mp.ListLayers(p):
    print lyrx.name('')
    lyrx.visible = False

When I run the code above I receive the following message

File "<string>", line 4
  print lyrx.name('')
SyntaxError: invalid syntax

1 Answer 1


ArcGIS Pro uses Python 3.x, as such, the print command is a function. It requires you to use it like a function print(lyrx.name) where as in Python 2 you could get away with doing print lyrx.name

Note I've removed the ('')....I'm not sure what you're doing what that bit of code.

edit in regards to your comment: The arcpy "mapping" syntax between ArcMap and Pro has changed in regards to arcpy "mp". You'll want to read the help, specifically the map and layer class.

aprx = arcpy.mp.ArcGISProject(r"C:\path\to\aprx.aprx")
m = aprx.listMaps("name of your map")[0] #0= first map it finds that matches that name
lyrList = m.listLayers()
for lyr in lyrList:
   lyr.visible = False
  • I tried this out, but now it gives me this error..... Traceback (most recent call last): File "<string>", line 2, in <module> IndexError: list index out of range
    – Matt A.
    Nov 20, 2017 at 13:03
  • You'll need to do some reading on how listMaps works off the project class: how to use the wild card search and the return type.
    – KHibma
    Nov 20, 2017 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.