Hello.
I am trying to use arcpy to list all of the layers in a group to apply symbology to all of them at once. When I use the arcpy.mapping.ListLayers(mxd, "Group Layer", df), it only returns the name of the group layer and not the layers within the group, so I am unable to iterate through them. I've tried several different queries, but all I seem to get it to do is list every single layer in the document (not what I want) or just the group layer name (also not what I want).
Does anyone know how to specify it to list all of the layers in the group? The ArcGIS help tells me it should be able to do that, listing first the name of the group layer followed by each layer within the group, but it is not working for me.
Hey Andrew,
Here's a snippet from some python that I use to export all of the layer files from an MXD. I'm sure you can modify for your own purpose.
for df in arcpy.mapping.ListDataFrames(mxd, ""):
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
if lyr.isFeatureLayer or lyr.isRasterLayer or lyr.isGroupLayer:
print "Layer: " + lyr.name
try:
lyr.saveACopy(lyr_dir+lyr.name+".lyr")
except:
print lyr.name + " had a little issue"
Thanks! I'll play with it when I'm back in the office.