I am looking for a way to ungroup a group layer using arcpy... (instead of having to open the mxd and right-click on the layer to choose "Ungroup"...)

mxd = arcpy.mapping.MapDocument(pathToMyMxd)
df = mxd.activeDataFrame

newLayer = arcpy.mapping.Layer(pathToMyLayerFile)
arcpy.mapping.AddLayer(df, newLayer, "BOTTOM")


layers = arcpy.mapping.ListLayers(df)
for layer in layers:
    if layer.isGroupLayer:
        # layer.ungroup()???

If the layer is a group layer then it should support ListLayers, from this then you can iteratively move layer and then finally, after all layers are moved out then remove the layer.

The reference layer for move layer should be the group layer, then the moved layers will (by default) go before the group layer.

I know it's not a one-liner but is effectively what you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.