Can anyone post the code to move a layer to a SUB-group-layer?
The following code (courtesy of https://gis.stackexchange.com/questions/475584/move-an-existing-layer-into-a-group-layer-using-arcpy...) works fine for copying the layer to a top-level group-layer, but I can't get it working for a group layer within another group layer e.g. MyGroupLayer/SubGroupA
Thanks,
Shane
lyr_to_move = mp.listLayers("My Layer Name")[0] group_layer = mp.listLayers("MyGroupLayer")[0] # Use this to move layers (but not into a group layer) #mp.moveLayer(group_layer, lyr_to_move, "AFTER") # Use this to move a layer into a group layer mp.addLayerToGroup(group_layer, lyr_to_move, "AUTO_ARRANGE")
Hi @Shane_EU, the following should work:
aprx = arcpy.mp.ArcGISProject("CURRENT")
mp = aprx.listMaps("Map")[0]
lyr_to_move = mp.listLayers("Airports")[0]
group_layer = mp.listLayers("SubGroup")[0]
# Use this to move a layer into a group layer
mp.addLayerToGroup(group_layer, lyr_to_move, "AUTO_ARRANGE")
# Remove layer from map
mp.removeLayer(lyr_to_move)
Before script:
After script: