HOW TO

Use Python to list the data sources of all layers in the table of contents of a map document

Last Published: January 30, 2021

Summary

The instructions below describe the steps to use Python code to list the data source for each layer in an MXD’s table of contents.

Procedure

  1. Open the MXD that contains the layers to use for the listing.
  2. Open the Python window by clicking the Python button on the Standard toolbar.

    [O-Image]
  1. Paste the following code into the Python window:
    import arcpy
    mxd = arcpy.mapping.MapDocument("CURRENT")
    for lyr in arcpy.mapping.ListLayers(mxd):
        if lyr.supports("DATASOURCE"):
            print "Layer: " + lyr.name + "  Source: " + lyr.dataSource
    Example:

    [O-Image]
  2. Press Enter. The code prints the layer name and source for all layers in the MXD.

    [O-Image]

Article ID:000011530

Software:
  • ArcMap 10 x
  • ArcMap 10 0

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic