English
Continue in the app
Be The First To Get Support Updates
Want to know about the latest technical content and software updates?

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

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]

Related Information

Last Published: 1/29/2021

Article ID: 000011530