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?
Solved! Go to Solution.
A feature class, or any data source, has no idea what MXD is being used to connect to it. With DBMSs, one could look at teasing out some information on what machines are connecting to specific data sets, but that would not give any insight into whether foo.mxd or bar.mxd.
The only way to obtain the information you are after would be to search for all MXDs across the client's systems, and then use ArcPy to open those MXDs and start exporting all of the data sources tied to all of the layers in the MXDs.
Are the MXDs in one folder?
They are not.
A feature class, or any data source, has no idea what MXD is being used to connect to it. With DBMSs, one could look at teasing out some information on what machines are connecting to specific data sets, but that would not give any insight into whether foo.mxd or bar.mxd.
The only way to obtain the information you are after would be to search for all MXDs across the client's systems, and then use ArcPy to open those MXDs and start exporting all of the data sources tied to all of the layers in the MXDs.
I would suggest using a script similar to those that find broken layer files. Something like:
import arcpy
import os
from arcpy import env
lyrFiles = {}
# set variables
path = r'C:\Path\to\mxds'
# iterates through folder and lists feature layers
for fileName in os.listdir(path):
fullPath = os.path.join(path,fileName)
if os.path.isfile(fullPath) and fileName[-3:].lower() == 'mxd':
mxd = arcpy.mapping.MapDocument(fullPath)
print fullPath
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.isFeatureLayer:
print "\t " + lyr.dataSource
# count layer files using dictionary
if lyr.dataSource not in lyrFiles.keys():
lyrFiles[lyr.dataSource] = 1
else:
lyrFiles[lyr.dataSource] += 1
print
for k, v in lyrFiles.items():
print k, v
To help the "broken link" option work, try to temporarily rename the fgdb you are using to force a break. However, if there are locks, a rename may be blocked.
We have that issue (locks) when trying to replace fgdb's that are being accessed by ArcGIS Server services. In that case, one of my steps is checking all the service mxds to see if they are accessing certain feature classes or the fgdb, and in my case shutting down the services before renaming /replacing. Something like that could be modified to search for target data sources and searching thru mxds.
I'm out of the office right now so can't grab my code, but I think what you are asking us doable.
on the broken link option, I have a tool that can inventory all data and list paths, etc. might help get you started.