HOW TO

Move feature layers into a group layer in ArcGIS Pro Contents using ArcPy

Last Published: March 5, 2025

Summary

In ArcGIS Pro, organizing layers within the Contents pane helps improve map management and visualization. Moving a feature layer into a group layer organizes related datasets. While this can be performed manually, automating the process using Python improves efficiency, particularly when working with multiple layers.

Complete the workflow provided to move a feature layer into a group layer within the Contents pane using Python in ArcGIS Pro.

Procedure

  1. In ArcGIS Pro, navigate to the Analysis tab on the top ribbon. In the Geoprocessing group, click the drop-down menu next to Python and select Python Window.
  2. In the Python window, insert the commands as follows:
    1. To import the ArcPy module, which provides access to ArcGIS Pro's geoprocessing tools and map automation functions:
import arcpy 
  1. To specify the current ArcGIS Pro project and map:
aprx = arcpy.mp.ArcGISProject("CURRENT")
mp = aprx.listMaps()[0]
  1. To assign the layers to be grouped into an array variable (replace <Layer_Name> with the name of the layer to be moved):
#For single layer
layer_names = ["<Layer_Name>"]

#For multiple layers
layer_names = ["<Layer_Name>", "<Layer_Name>", "<Layer_Name>"]

layers_to_move = [lyr for lyr in mp.listLayers() if lyr.name in layer_names]
  1. To retrieve the group layer (replace <Group_Name> with the name of the group layer to be moved):
group_list = mp.listLayers("<Group_Name>")
group_layer = group_list[0]
  1. To move the specified layers from Step 2(c) into the target group layer using the addLayerToGroup() function:
for lyr in layers_to_move:
    mp.addLayerToGroup(group_layer, lyr, "AUTO_ARRANGE")
    print(f"Layer '{lyr.name}' successfully moved into group '{group_layer.name}'.")
Note: 
This script uses auto arrange for layer placement. To change the placement of the added layer within the group layer, refer to ArcGIS Pro: Methods for instructions and more information.

The code below demonstrates the full working script to move the feature layers into the group layer.

import arcpy

aprx = arcpy.mp.ArcGISProject("CURRENT")
mp = aprx.listMaps()[0]

layer_names = ["TestLayer1", "TestLayer2", "TestLayer3"]

layers_to_move = [lyr for lyr in mp.listLayers() if lyr.name in layer_names]

group_list = mp.listLayers("TestGroupLayer")
group_layer = group_list[0]

for lyr in layers_to_move:
    mp.addLayerToGroup(group_layer, lyr, "AUTO_ARRANGE")
    print(f"Layer '{lyr.name}' successfully moved into group '{group_layer.name}'.")

Article ID: 000034956

Software:
  • ArcGIS Pro 3 3
  • ArcGIS Pro 3 2
  • ArcGIS Pro 3 4

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options