Find datasets associated with mxd's

09-14-2016 02:27 AM
New Contributor III

We need to have a data clear out, and want to find which datasets are associated with numerous mxd's.  Does anyone know if there is an automatic way of listing the associated dataset.

It would also be good if we could flag up if the dataset link is valid or a broken link

If anyone has any ideas or suggestions on how this could be achieved then it would be good to hear from you.

0 Kudos
3 Replies
Esri Contributor

You can automate this with ArcPy.

Here is an example of a script that:

1. Gathers all of the mxds in a workspace

2. Iterates through each mxd and lists all of the layers in the mxd

3. Prints out a message about each layer (including the path to the data source and if the link to the data source is broken)

import arcpy, os

#Set the workspace where you will list all of the MXDs
arcpy.env.workspace = r"C:\Path\to\Workspace"

#Loop through each mxd in the workspace
for mxd in arcpy.ListFiles("*.mxd"):
    #Create path to the workspace
    map = os.path.join(arcpy.env.workspace, mxd)
    #Create a map document object
    m = arcpy.mapping.MapDocument(map)
    #List all of the layers in the map document
    lyrs = arcpy.mapping.ListLayers(m)
    #Loop through each layer in the map document and print out a message
    for lyr in lyrs:
        print "Map: {} Layer: {} Data Source: {} Broken?:{}".format(mxd,lyr,lyr.dataSource, lyr.isBroken)

Here are some links to the documentation that you may find useful:

Folks in the Python‌ group may have other suggestions.

MVP Regular Contributor

One note on the dataSource property of a layer I've found while doing this:

Not all layers support the dataSource property (for example, annotation classes and web services), so it is good practice to test for this ahead of time using the supports method.

if lyr.supports("DATASOURCE"):‍
    print "Map: {} Layer: {} Data Source: {} Broken?:{}".format(mxd,lyr,lyr.dataSource, lyr.isBroken)
MVP Esteemed Contributor

you can check out my /blogs/myAlaskaGIS/2015/08/31/python-addin-for-data-inventory-and-broken-link-repair?sr=search&searc...‌ which might help.  One of the tools just takes inventory of datasources.  Feel free to grab the script and modify if needed.