0

I am using ArcGIS Pro with Python 3.6.

I'm posting this as a new question because I've made significant headway in narrowing down the problem. I believe the issue is how ArcPy is used with ArcMap versus ArcGIS Pro.

Here is the error:

 Query = FULL_STREET_NAME LIKE '%'
Traceback (most recent call last):
  File "\\coacd.org\dfs\SWS\Code Enforcement\ACD Admin Operations\GIS\Operations\BSC Maps\Scripts\Python3compatible\BSCMapGenerator_v7.py", line 41, in <module>
    for lyr in mp.ListLayers(): #set visibility and remove older layers
AttributeError: 'list' object has no attribute 'ListLayers'
[Finished in 11.2s]

Here is a sample of the script:

workspace = "G:\\Code Enforcement\\ACD Admin Operations\\GIS\\Operations\\BSC_Maps\\AutoLayerFiles.gdb"
arcpy.env.workspace = workspace
arcpy.env.overwritOutput = True #overwrite existing files
aprx = arcpy.mp.ArcGISProject("G:\\Code Enforcement\\ACD Admin Operations\\GIS\\Operations\\BSC Maps\\BSC_Template_Auto_Generate_PRO_v1.aprx")
mp = aprx.listMaps(aprx)
#df = arcpy.mp.ListDataFrames(aprx)[0] # address location data frame and turn on select layers
location = arcpy.GetParameterAsText(0)
location = location.upper() #convert to uppercase
caseNumber = arcpy.GetParameterAsText(2)
userName = getpass.getuser().upper()
date = time.strftime("%m/%d/%Y")  #added to map
expression = "FULL_STREET_NAME LIKE '" + location + "%'" #this is an SQL expression and can be modified as necessary
expression2 = "LAND_USE_ID LIKE '%'"
arcpy.AddMessage("Query = " + expression)
visibleStructuresLayers = ["TRANSPORTATION.street_segment","Structures","Subject Property","Parcels","Lakes"]
visibleLocationLayers = ["TRANSPORTATION.street_segment","Subject Tract","Parcels","Lakes"]
visibleRoadMapLayers = ["Subject Tract","Subject Property","Lakes","Basemap","OpenStreetMap"]

locationMapScale = arcpy.GetParameterAsText(3) #default 2000
roadMapScale = arcpy.GetParameterAsText(4) #default 5500 
structureMultiplier = (arcpy.GetParameterAsText(5) # default 1.1 (110% of parcel size) #float(arcpy.GetParameterAsText(5))

#-----------REFRESH TEMPLATE------------------
#arcpy.AddMessage("Refreshing template...")
#arcpy.Delete_management("Subject Tract")  #removes instances from memory (not from map)
#arcpy.Delete_management("Subject Property")

for lyr in mp.ListLayers(aprx): #set visibility and remove older layers
    lyr.visible = False
    if lyr.name == "Subject Tract":
        arcpy.mp.RemoveLayer(lyr)
    if lyr.name == "Subject Property":
        arcpy.mp.RemoveLayer(lyr)
    if lyr.name in visibleLocationLayers:
        lyr.visible = True

For reference, it used to read like this in 2.7 were df was the arcpy.mapping.listdataframes(mxd):

arcpy.AddMessage("Refreshing template...")
arcpy.Delete_management("Subject Tract")  #removes instances from memory (not from map)
arcpy.Delete_management("Subject Property")

for lyr in arcpy.mapping.ListLayers(mxd, "", df): #set visibility and remove older layers
    lyr.visible = False
    if lyr.name == "Subject Tract":
            arcpy.mapping.RemoveLayer(df, lyr)
    if lyr.name == "Subject Property":
        arcpy.mapping.RemoveLayer(df, lyr)
    if lyr.name in visibleLocationLayers:
        lyr.visible = True

marked as duplicate by Vince, aldo_tapia, PolyGeo arcpy Aug 1 at 20:47

This question was marked as an exact duplicate of an existing question.

  • 1
    structureMultiplier = (arcpy.GetParameterAsText(5) perhaps this is causing the error – aldo_tapia Aug 1 at 20:40
  • 1
    Always look to the line ABOVE the syntax error to see it it's an open paren issue. – Vince Aug 1 at 20:41
  • The code that you are presenting would get much closer to being the code snippet that is required to get help here if you were to remove most of those import and GetParameterAsText lines from it. This does not mean that you should remove them from your actual code, which should be kept separate from any code snippets that you present. I think focusing down to code snippets means you will often find answers to your own questions before posting them, and any you do need to post will have more re-use for others encountering them later. – PolyGeo Aug 1 at 22:33
5

No, the problem does not have anything to do with ArcGIS or arcpy. SyntaxError means that there is a problem with the syntax of your program and it identifies this error before running anything. In your case, you have an opening parenthesis that should not be there and is triggering the error. On the line:

structureMultiplier = (arcpy.GetParameterAsText(5) # default 1.1 (110% of parcel size) #float(arcpy.GetParameterAsText(5))

you are opening a parenthesis right before arcpy.GetParameterAsText(5) but are never closing it. Remove it so your line looks like:

structureMultiplier = arcpy.GetParameterAsText(5) # default 1.1 (110% of parcel size) #float(arcpy.GetParameterAsText(5))

In your code mp is a list with all the maps on your aprx project. You want to call the listLayers() method for a map and not for the list of maps. I hope the following code, taken from the documentation, helps elucidate the situation:

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
for m in aprx.listMaps():
    print("Map: {0} Layers".format(m.name))
    for lyr in m.listLayers():
        if lyr.isBroken:
            print("(BROKEN) " + lyr.name)
        else:
            print("  " + lyr.name)
del aprx
  • Oh dang. I fixed that and I'm getting a new error in the same spot. – Anthony Stokes Aug 1 at 20:53
  • 1
    @AnthonyStokes did you write original python 2.7 code? Or is from someone else? Maybe original author can help you – aldo_tapia Aug 1 at 21:02
  • 2
    @AnthonyStokes I just edited my answer. On an additional note, I encourage you to read the Esri documentation. Everything is really well documented and they have useful examples. If you still have troubles after reading the documentation, check here or in GeoNet if somebody else have experienced the same issues; it is very likely somene had. It feels like your last three questions on this site have been a community debugging of your code where each edit represents a new error. Also, make sure to check StackOverflow for questions related to Python programming! – Marcelo Villa Aug 1 at 21:07
  • 1
    Yeah I think the problem was that I didn't know whether I had issues with analyze tools for pro or python syntax or environments and so each question started as a separate issue that then led into simple python errors. I helped write these scripts but I'm not formally trained. I also only script on occasion so I tend to forget about things. I'll do my own debugging and see how far I get. – Anthony Stokes Aug 1 at 22:46

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