I'm trying to apply a definition query to multiple layers within a Layer Group 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's a similar question posted on SE that applies the same logic of applying a definition query to a Layer Group, however I'm using ArcGIS Pro and the post refers to ArcMap. 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
Here's an illustration of my Layer Group: