group layer not iterable

2202
3
Jump to solution
08-09-2017 11:56 AM
mikeharol
New Contributor III
for layer in m.listLayers():
    if layer.isGroupLayer and layer.name == "AerialLayers":
        for subLayer in layer:

I use to be able to iterate the groupLayer with arcpy.mapping but now with arpy.mp i get the following error:
TypeError: 'Layer' object is not iterable

Any insights appreciated.

Thanks

Mike

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
mikeharol
New Contributor III

Turns out you have to call listLayers() on the grouplayer.  Wasn't clear to me in the documentation i read.

for layer in ma.listLayers():
    if layer.isGroupLayer and layer.name == "AerialLayers":
        for subLayer in layer.listLayers():
            print(subLayer)

View solution in original post

0 Kudos
3 Replies
mikeharol
New Contributor III

Turns out you have to call listLayers() on the grouplayer.  Wasn't clear to me in the documentation i read.

for layer in ma.listLayers():
    if layer.isGroupLayer and layer.name == "AerialLayers":
        for subLayer in layer.listLayers():
            print(subLayer)
0 Kudos
by Anonymous User
Not applicable

Hi Mike, glad to hear that listLayers() is working for you.  Also, a good place for ArcPy questions is the Python group here:  https://community.esri.com/community/developers/gis-developers/python 

mikeharol
New Contributor III

thanks

0 Kudos