Friday, July 1, 2011

ArcPy - Looking inside Group Layers

A group layer contains other layers. Group layers help organize related kinds of layers in a map and can be used to define advanced drawing options. For example, suppose you have two layers on a map representing railroads and highways. You could group these layers together and name the resulting layer Transportation Networks. If you need to, you can even create nested group layers (groups of group layers). (source: esri)

Now, let's say you have to do some analysis on layers inside the group layers, you can loop the layers as follows:


import arcpy
mxdPath = r"c:\temp\mapDoc.mxd"
mxd = arcpy.mapping.MapDocument(mxdPath)
layers = arcpy.mapping.ListLayers()
for layer in layers:
if layer.isGroupLayer:
for subLayer in layer:
print "This layer is in a group layer: " + str(subLayer.name)



This will print a list of layer contained in a groupLayer.