HOW TO

List all maps referenced in a layout in an ArcGIS Pro project using Python

Last Published: February 24, 2023

Summary

In an ArcGIS Pro project, a single layout can contain multiple map frames, each referencing a different map. Identifying the maps when a layout is opened can be done through visual inspection in the Contents pane in ArcGIS Pro.

An alternative to identifying maps referenced in a layout, especially when multiple maps are involved, is by using ArcPy. The following procedure describes how to programmatically list all maps referenced in a layout in an ArcGIS Pro project using Python.

Procedure

  1. In ArcGIS Pro, open the Python window. Refer to ArcGIS Pro: Python window for more information.
  2. Import the necessary modules.
import arcpy
mapDict= {}
  1. Specify the currently open project.
aprx = arcpy.mp.ArcGISProject("CURRENT")
  1. Create a loop to search for all the map frames in all layouts in the project, and insert them into a dictionary parameter.
for lyt in aprx.listLayouts():
    for m in lyt.listElements("MAPFRAME_ELEMENT"):
        if lyt.name in mapDict:            
            mapDict[lyt.name].append(m.map.name)
        else:
            mapDict[lyt.name]=[m.map.name]
  1. Show the result using the print function.
print(mapDict)

The code block below demonstrates the full script.

import arcpy
mapDict= {}

aprx = arcpy.mp.ArcGISProject("CURRENT")

for lyt in aprx.listLayouts():    
    for m in lyt.listElements("MAPFRAME_ELEMENT"):
        if lyt.name in mapDict:            
            mapDict[lyt.name].append(m.map.name)
        else:
            mapDict[lyt.name]=[m.map.name]

print(mapDict)

Article ID: 000029323

Software:
  • ArcGIS Pro 3 0
  • ArcGIS Pro 2 x

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