HOW TO

Get a list of layers in maps in an ArcGIS Pro project using ArcPy

First Published: June 8, 2026
Last Published: June 8, 2026

Summary

It is sometimes necessary to take an inventory of what is in ArcGIS Pro projects just to obtain some simple information, such as the names of the maps and layers in a particular project. This article describes some ways to do this, including a simple script that:

  • lists the maps in a project and selects the first one
  • lists the layers in the map
  • writes the name of the map
  • writes the names of all the layers in the map to a file

Also included is a slightly more complex script tool that creates a file that lists the names of all the maps and layers in the project.

Procedure

Standalone script example

See the attached file for a sample toolbox.

import arcpy

arcpy.env.workspace = r"<YourOutputDirectory>"

# Create an aprx object
aprx = arcpy.mp.ArcGISProject("CURRENT")

# List maps in the project and select the first one
m = aprx.listMaps()[0]

# List the layers in the map and then store in a variable
lyr = m.listLayers()

# Open a new file and set it to write mode
f = open(r"<YourFileName>.txt", "w") 

# Write the name of the map on the first line
f.write("Layers contained in Map: " + m.name + "\n")
f.write("--------------------------------------------------" + "\n")

# Create a for loop to get all of the layer names and then write to the file
for x in lyr: 
    f.write(x.name + "\n")

# Close out the file
f.close()

Script Tool Example (see attached file for sample toolbox):

# Import modules
import arcpy

# Create user defined variables for script tool
workspace = arcpy.GetParameterAsText(0)
txtFileName = arcpy.GetParameterAsText(1)

# Open a new file and set it to write mode and append a .txt to the input so that a txt file is created
f = open(txtFileName + ".txt", "w")

#Set workspace for output text file
arcpy.env.workspace = workspace

# Create an aprx object
aprx = arcpy.mp.ArcGISProject("CURRENT")


# Write the path of the APRX file to give more context to the output file
f.write("List of Maps and Layers for project located at: " + aprx.filePath + "\n\n")


# Loop through all maps and layers in the project and write to the text file
for m in aprx.listMaps():
    f.write("Layers contained in map: " + m.name +"\n")
    f.write("--------------------------------------------" + "\n")
    for lyr in m.listLayers():
        f.write(lyr.name + "\n")
    f.write("--------------------------------------------" + "\n\n")

# Close out the file
f.close()

Article ID: 000041430

Software:
  • ArcGIS Pro

Get support with AI

Resolve your issue quickly with the Esri Support AI Chatbot.

Start chatting now

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Start chatting now

Go to download options