Skip to content

Instantly share code, notes, and snippets.

@alexfriant
Last active August 4, 2017 23:03
Show Gist options
  • Save alexfriant/514220b4c35b196946af72d9662bc795 to your computer and use it in GitHub Desktop.
Save alexfriant/514220b4c35b196946af72d9662bc795 to your computer and use it in GitHub Desktop.
Give this script an entire Geodatabase and it reports a list of it's feature classes and whether or not Editor Tracking is enabled.
###############################################################################
#
# Requirements: You'll need ArcGIS Desktop 10.1 or higher with Python 2.7+
# Use as a ArcToolbox Script Tool. Add the parameters as needed.
#
# Give this script an entire Geodatabase and it reports a list of its feature
# classes and whether or not Editor Tracking is enabled.
#
# The output is useful for managing Editor Tracking for a large number of
# feature classes.
#
# Feel free to use, rewrite, and distribute as you wish.
###############################################################################
# load the esri arcgis python module
import arcpy #you need to have arcgis 10.1 or newer installed on your machine to do this
import datetime, time
## GRAB PARAMETERS FROM YOUR ARCTOOLBOX SCRIPT
workspace = arcpy.GetParameterAsText(0).replace("\\","/") # this is the geodatabase you want a report on
out_path = arcpy.GetParameterAsText(1).strip().replace("\\","/") # this is the directory where you want your report to go
### DEFINE FUNCTIONS
# for processing through a list of feature classes
# it gets and returns the results of arcpy tool "describe"
# in the form of FC NAME, COUNT
def processGDBfc(fcList, dataset=''):
results = ""
if len(fcList) > 0:
for fc in fcList:
desc = arcpy.Describe(fc)
if dataset <> '':
temp = dataset + "," + fc + "," + str(desc.editorTrackingEnabled)
else:
temp = "root," + fc + "," + str(desc.editorTrackingEnabled)
arcpy.AddMessage(temp)
results = results + temp + "\n"
return results
# for processing through a list of datasets
# it gets and returns the results of "processGDBfc" above
def processGDBdataset(dsList):
results = ""
if len(dsList) > 0:
for ds in dsList:
arcpy.AddMessage("\nDataset: " + ds)
fcList = listFeatureClasses(ds)
results = results + processGDBfc(fcList, ds)
return results
# returns a list of feature classes for a given dataset
# if no dataset name is given then the default is the GDB root
def listFeatureClasses(dataset=''):
temp = arcpy.ListFeatureClasses('','All',dataset)
temp.sort()
return temp
# returns a list of datasets for a given workspace environment
def listDatasets():
temp = arcpy.ListDatasets()
temp.sort()
return temp
### INTIALIZE WORKSPACE AND OUTPUT FILE
# assign GDB parameter as the environment workspace
arcpy.env.workspace = workspace
# set up output file to be written to the either the GDB's home directory or the designated directory
# name the output file with GDB name and time stamped
gdb_name = workspace[workspace.rfind("/")+1:].replace(" ","_")
ts = datetime.datetime.fromtimestamp(time.time()).strftime('%Y%m%d_%H%M%S')
fileName = "/gdb_data_report-" + gdb_name + "-" + ts + ".csv"
if not out_path: #handle whether or not an output path was specified
gdb_path = workspace[:workspace.rfind("/")]
output_file = gdb_path + fileName
else:
output_file = out_path + fileName
# initialize output string variable for the output file
output = workspace + ",,\n" #provides the path name of the GDB, useful for comparing numbers between different GDB's in a spreadsheet
output = output + "dataset,feature_class,editor_tracking_status\n"
# give the tool's dialog box the GDB context useful for the user
arcpy.AddMessage("\nReport for: " + gdb_name)
### ACTUAL ITERATION BEGINS HERE
# begin by iterating through all feature classes at the GDB's root level first
fcList = listFeatureClasses('')
if fcList > 0:
arcpy.AddMessage("\nRoot of Geodatabase:")
output = output + processGDBfc(fcList, '') #the second parameter sets dataset as root in the GDB
# end by iterating through each feature class in each dataset
dsList = listDatasets()
output = output + processGDBdataset(dsList)
### OUTPUT
# generate output to output file
file = open(output_file, "w")
file.write(output)
file.close()
arcpy.AddMessage('\nOutput to file: ' + output_file.replace("/","\\") + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment