3

Trying to remove any unused feature classes contained throughout multiple geodatabases. Want to check and see if each feature class is being used in an MXD. Is there any tool/script/methodology to do this?

I think it is a one way street where feature classes do not carry MXD usage information. If that is the case, any other ideas on how this might be accomplished?

closed as off-topic by PolyGeo Mar 1 '16 at 22:33

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • This sounds like a backwards exercise. Wouldn't it be better to evaluate the data see what should be used, move the pieces which shouldn't be used elsewhere, then review your maps for invalid references? – Vince Jan 7 '16 at 15:51
  • I agree with @Vince: another intuitive way could be opening all MXD's and accounting for the .lock files created by listing. Hopefully, any dataset that doesn't have a lock file created is not being used by any of the MXDs. – yanes Jan 7 '16 at 16:10
  • Identifying all referenced sources should be scriptable in Python without needing to analyze lock files, but you should also include visibility and scale dependency parameters for each, then review for best practice. – Vince Jan 7 '16 at 16:26
2

I used this script about three years ago for a similar purpose. It looks at an mxd and exports all of the active layers to a File GDB. It was very helpful when finishing projects and handing over working files to clients. It will probably need to be modified somewhat to meet your needs and set up as a script tool in an arcToolbox, or you can hardcode the get parameters as text lines. Again, it has been a few years since I've used it so there might be some kinks. Also, you need to create clip feature class to cover the extent of your feature classes.

# Script Name: Clip Multiple Feature Classes
# Description: Clips one or more shapefiles
#              from a folder and places the clipped
#              feature classes into a geodatabase.
# Created By:  Insert name here.
# Date:        Insert date here.
# Import ArcPy site-package and os modules
#

import arcpy 
import os
import string
import sys
from arcpy import mapping


# Set the input workspace
#arcpy.env.workspace = arcpy.GetParameterAsText(0)

mapDocument = arcpy.GetParameterAsText(0)

# Set the clip featureclass--this should cover the extent
clipFeatures = arcpy.GetParameterAsText(1)

# Set the output workspace
outWorkspace = arcpy.GetParameterAsText(2)

# Set the XY tolerance
clusterTolerance = arcpy.GetParameterAsText(3)

fcList = []

mxd = mapping.MapDocument(mapDocument)
for df in mapping.ListDataFrames(mxd):
    for lyr in mapping.ListLayers(mxd, "", df):
        if lyr.supports("DATASOURCE"):
            if lyr.dataSource not in fcList and ".gdb" in lyr.dataSource:
                fcList.append(lyr.dataSource)

del df
del lyr
del mxd

try:
    for fc in fcList:
        featureClassname = arcpy.ValidateTableName(os.path.basename(fc), outWorkspace)
        outFeatureClass = os.path.join(outWorkspace, featureClassname)

        if os.path.basename(fc) != os.path.basename(clipFeatures) and not arcpy.Exists(outFeatureClass):
            arcpy.AddMessage("Currently clipping the " + str(os.path.basename(fc)) + " feature...")
            arcpy.Clip_analysis(fc, clipFeatures, outFeatureClass)#, clusterTolerance)

except:
    arcpy.AddMessage(arcpy.GetMessages(2))
    print arcpy.GetMessages(2)

txtFile = open(os.path.dirname(outWorkspace) + os.sep + "Logfile.txt", 'w')
arcpy.env.workspace = outWorkspace

msg = "The " + os.path.basename(outWorkspace) + " contains the following features.\n\n"
txtFile.write(msg)

i = 0

for fc in arcpy.ListFeatureClasses():
    i += 1
    rowCount = str(i).zfill(len(str(len(arcpy.ListFeatureClasses())))) + ". "
    txtFile.write(rowCount + fc + "\n")
txtFile.close()

Not the answer you're looking for? Browse other questions tagged or ask your own question.