English

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:
     
    Code:
    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]
 
  1. Press Enter. The code prints the layer name and source for all layers in the MXD.

    [O-Image]