I'm trying to apply a definition query to a Layer Group (containing several feature classes) by using the following script where I would simply change the values for my 'SUBCODE' field
import arcpy
#Variables to form defintion query
field = '"SUBCODE"'
values = "'1152','1153'"
#concatenate query syntax
queryStr = str(field) + "=" + str(value)
#Specify the aprx project (CURRENT), dataframe (Layers)
p = arcpy.mp.ArcGISProject("CURRENT")
m = p.listMaps("Map_3D")[0]
#Apply defintion query to specified layer group
for lyr in m.listLayers( "3D Layers")[0]:
if lyr.supports("DEFINITIONQUERY"):
lyr.definitionQuery = queryStr
arcpy.RefreshActiveView()
del aprx
This is the error I'm receiving when I run this in Arcpy:
Traceback (most recent call last):
File "<string>", line 12, in <module>
IndexError: list index out of range
There are some migration from arcpy.mapping to ArcGIS Pro I'm having trouble with - http://pro.arcgis.com/en/pro-app/arcpy/mapping/migratingfrom10xarcpymapping.htm
Any help on this script would be greatly appreciated!
Solved! Go to Solution.
when you list layer and grab the first item (index 0) you have a single element and not a list. Remove the "[0]" at the end of line 12
when you list layer and grab the first item (index 0) you have a single element and not a list. Remove the "[0]" at the end of line 12
That was it, thanks so much!!