HOW TO
An ArcGIS Pro map consists of multiple layers, each representing different datasets. Prioritizing the layers helps in data management and organization, ensuring pertinent layers are used, updated, or shared.
This article describes the workflow to list the selected layers from an ArcGIS Pro map using ArcPy.
Note: This workflow requires a full script to run in the ArcGIS Pro Python window. The indents must be retained as portrayed in the code block.
Note: Select the features interactively before running the Python code. Refer to ArcGIS Pro: Select features for instructions.
import arcpy
def get_selected_layers():
active_map = arcpy.mp.ArcGISProject("CURRENT").activeMap
layers = active_map.listLayers()
selected_layers = []
for layer in layers:
selection_set = layer.getSelectionSet()
if selection_set:
selected_layers.append(layer.name)
return selected_layers
if __name__ == "__main__":
selected_layers = get_selected_layers()
print("Selected Layers:")
for layer_name in selected_layers:
print(layer_name)
The code below demonstrates the full working script.
import arcpy
def get_selected_layers():
active_map = arcpy.mp.ArcGISProject("CURRENT").activeMap
layers = active_map.listLayers()
selected_layers = []
for layer in layers:
selection_set = layer.getSelectionSet()
if selection_set:
selected_layers.append(layer.name)
return selected_layers
if __name__ == "__main__":
selected_layers = get_selected_layers()
print("Selected Layers:")
for layer_name in selected_layers:
print(layer_name)
The image below shows the list of the selected layers printed in the Python window.
Get help from ArcGIS experts
Download the Esri Support App