Hi All,
I've been trying to ungroup a group layer in TOC using Arcpy with no luck. There is no such function in arcpy so the approach I am trying to do is moving layer by layer out of the group and place them all on top of TOC.
However I can't get the loop through layers working.
The mxd structure is:
And I want to have:
The code below only moves the last layer from the TopGroup:
import arcpy, os
MapMainFolder = r"Z:\Workspace"
for (root, dirs, files) in os.walk (MapMainFolder):
for fileName in files:
if os.path.splitext (fileName)[1] == ".mxd":
arcpy.AddMessage (fileName)
fullPath = os.path.join (root, fileName)
mxd = arcpy.mapping.MapDocument (fullPath)
print fileName
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.name != lyr.longName:
moveLayer = lyr
print moveLayer
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.name == lyr.longName:
refLayer = lyr
print refLayer
arcpy.mapping.MoveLayer(df, refLayer, moveLayer, "BEFORE")
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
mxd.save()
Anyone has any idea on:
- how to loop through the layer list?
- how use a different approach?
The reason I need to ungroup the layers is to avoid having all layers rasterized when exporting to an Illustrator file.
Thanks for help!