I have to programmatically sort several layers in an .mxd project that are each placed in the same group layer. I have found a script that partially works by sorting all layers in the TOC (Arc GIS 10.1 - How to sort Layers ascending at TOC in "List by drawing order").
mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd) # Assuming one data frame group_lyr = [lyr for lyr in arcpy.mapping.ListLayers(mxd) if lyr.isGroupLayer] # The temp group layer should be the only one lyr_names = sorted(lyr.name for lyr in arcpy.mapping.ListLayers(mxd) if lyr.isFeatureLayer) for name in lyr_names: arcpy.mapping.MoveLayer(df, group_lyr, arcpy.mapping.ListLayers(mxd, name), "BEFORE") mxd.save()
However I am having trouble to apply this to a specific group layer (in this case 'GroupLayer1') as indicated in the illustration below.
Is there a solution that allows for sorting only the layers in a specific group layer?