Thursday, 12 February 2015

Count number of group layers or Layers inside group layer using ArcPy?



I am looking for a way of counting the amount of layers within a group layer


I have an empty group layer inside my map and I am looking for a way of initiating a process if there are 0 layers inside the group layer. So for I have been listing layers inside layer. But if there is nothing inside .. there is nothing to loop through.


Is there a simple way to count the amount of sub layers inside a group ? For example I have a MXD with one empty group layer inside it. I want to count the amount of layers inside the group layer So far I am only able to access the layer like this


import arcpy
group = []
mxd = arcpy.mapping.MapDocument(r"C:\Users\jackw_000\Documents\mxd\layer_mapV2.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
for lyr in arcpy.mapping.ListLayers(mxd, "my_group_layer", df):

group.append(lyr)

print group

Returns ['My_group_layer']


When I print out the list it returns my_group_layer... . I am missing something.. ? A sub note , I am running this from IDLE , so at no time I am in seeing whats inside the TOC interface




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...