5

I know it is possible to list the paths of feature classes that are in an MXD using arcpy. But is it possible to do the reverse -- to list all the MXDs that a feature class is in?

I am trying to organize very full file geodatabases that have>1000 feature classes in them. My client wants to keep those feature classes that are used in the most frequently used MXDs. To do this, I was thinking that maybe it was possible to run through every feature class and get a list of every MXD it is in and go from there. Can I do this?

asked Jan 3, 2018 at 21:03
2
  • 2
    If you have a list of all possible MXD locations, it would theoretically be possible to iterate through the MXDs using os.walk, and then use arcpy to identify the feature classes present in each and keep a running tally. Commented Jan 3, 2018 at 21:09
  • Being used in an mxd isn't saved in the Feature Class - are all the MXDs saved on a common server or shared drive, or are they across individual user systems? If they are all on the same drive, this could be accomplished by iterating through all MXDs in a single script Commented Jan 3, 2018 at 21:17

1 Answer 1

5

As mentioned in the comments, if you can get all the MXDs in a single location, you can run over each MXD and find each layer stored within. The below code will return a dictionary of layers' datasources used in each MXD of a directory and the MXD name which they're found in.

import arcpy
import os
mxdDir = r'C:\path\to\directory\of\MXDs'
mxdDict = {}
for mxd in os.listdir(mxdDir):
 mxdPath = os.path.join(mxdDir, mxd)
 mxdDoc = arcpy.mapping.MapDocument(mxdPath)
 for layer in arcpy.mapping.ListLayers(mxdDoc, "", ""):
 if layer.supports("DATASOURCE"):
 ds = layer.dataSource
 if ds not in mxdDict:
 mxdDict[ds] = [mxd]
 elif mxd in mxdDict[ds]:
 pass
 else:
 mxdDict[ds].append(mxd)
answered Jan 3, 2018 at 21:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.