I have a map object and I am trying to move an existing layer from that map object into a newly created group layer in the same map object.
aprx = arcpy.mp.ArcGISProject("Current")
mp = aprx.listMaps()[0]
lyr = mp.listLayers()[0]
group = mp.createGroupLayer("New Group")
I cannot find any documentation describing this. On the Map Documentation page it says this:
The moveLayer method will move a layer within a map and also into and out of group layers in the same map. The move_layer and reference_layer must reside in the same map. A layer cannot be moved from one map to a different map even within the same project. Use addLayer, addLayerToGroup, or insertLayer instead.
But it doesn't describe how. I'd rather not use addLayerToGroup
and then use removeLayer
(to remove the original layer) as this seems inefficient.