In a script, I'm creating a feature layer and trying to add it to a map in ArcGIS Pro 2.3.0. When I try to add it though, I get a ValueError. Any ideas why and how to fix it? m is the map object. The layer is created.
FWIW, I'm running the script in Spyder, Python 3.6.6, which I installed (maybe correctly, maybe not) in the default ArcGIS Pro environment. It seems to recognize the arcpy module, although there's no intellisense.
aprx = arcpy.mp.ArcGISProject(prj)
m = aprx.listMaps()[0]
target = m.listLayers('Cities Villages Twps')[0]
try:
target.definitionQuery = "NAME = 'Chicago'"
arcpy.CopyFeatures_management(target, 'GPP')
arcpy.MakeFeatureLayer_management('GPP', "Area501")
print(type("Area501")) # str
print(type(Area501)) # NameError: name 'Area501' is not defined
print(type(Area501[0])) # NameError: name 'Area501' is not defined
m.addLayer(Area501[0]) # NameError: name 'Area501' is not defined
except Exception:
print(arcpy.GetMessages())
print('\n')
tb.print_exc(limit=1, file=sys.stdout)
del aprx
ValueError
", when you get an error, always include the entire exception traceback as text (formatted as code{}
) in your question. 2 - Never ever usetry: except:
statements when posting questions here, you won't be able to see the entire exception traceback.