Select to view content in your preferred language

Feature class/shapefile dependencies

10-06-2016 02:47 PM
New Contributor II

I am working with ArcGIS Pro 1.3, as well as ArcGIS 10.4. Is there a tool that will find dependencies for a selected feature class or shapefile? For example, I would like to be able to select a feature class and a project file location (folder/sub-folders) and return the project files that reference the selected feature class, with results looking something like

Feature Class xyz is referenced by d:\myProject.mxd

0 Kudos
3 Replies
MVP Emeritus

No... there are tools by others, that allow you to examine featureclasses and return the projects, etc, that are used by them.

0 Kudos
MVP Honored Contributor

You can do it using Python:

>>> import os
... workspace = r'C:\junk' # starting directory
... lyr_dict = {} # empty dictionary
... for root, dirs, files in os.walk(workspace, topdown=True): # starting traversing directories
...     for file in files: # loop through file names
...         if file.endswith('.mxd'): # if it's an mxd
...             mxd = arcpy.mapping.MapDocument(os.path.join(root,file)) # make map object
...             lyrs = arcpy.mapping.ListLayers(mxd) # list layers
...             for lyr in lyrs: # loop through layers
...                 if lyr.supports('dataSource'): # if the layer supports dataSource property
...                     lyr_dict.setdefault(lyr.dataSource,[]).append(mxd.filePath) # add to dictionary‍‍‍‍‍‍‍‍‍‍‍

The above script creates a dictionary like {layer_path1:[mxd,mxd,mxd...], layer_path2:[mxd,mxd,mxd...]...}

MVP Emeritus

Hi Darren, nice script....adding it to my toolset.  I did make one addition on line 10 to eliminate some "false positives" which may be groups or some other type which grabs lyr.dataSource that are "empty/blank".  In my test, it was found in all the mxds and therefore mucked up my results.  I haven't tested it further (and there may be a better test), but this worked for my purposes......changing line 10 to

if lyr.supports('dataSource') and (len(lyr.dataSource) > 0) : # if the layer supports dataSource property but NOT zero length