Last active
August 30, 2017 22:53
-
-
Save alexfriant/71e076c5bedc4d70a2ae5be7da14ab8a to your computer and use it in GitHub Desktop.
Give this script a geodatabase (Personal, File, or SDE connection) and it will remove the "Geoprocssing History" contents from the Metadata in every Feature Class inside the geodatabase.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################# | |
# | |
# Requirements: You'll need ArcGIS Desktop 10.1 or higher with Python 2.7 | |
# | |
# Give this script a geodatabase (Personal, File, or SDE connection) and it will | |
# remove the "Geoprocssing History" contents from the Metadata in every Feature | |
# Class inside the geodatabase. | |
# | |
# Before you attempt to use/run this script, make sure you have read the section | |
# near the top called "MODIFIABLE VARIABLES HERE". | |
# | |
# Feel free to use, rewrite, and distribute as you wish. | |
# | |
################################################################################# | |
# Import arcpy module | |
import arcpy, os, string | |
## MODIFIABLE VARIABLES HERE | |
if __name__== "__main__": | |
## Use these variables if you are using this script in ArcToolBox. | |
## If you are running this script outside of ArcToolBox, then comment these two lines out, and read the next section. | |
the_gdb = arcpy.GetParameterAsText(0) | |
out_xml = arcpy.GetParameterAsText(1) | |
## Uncomment and modify to use these variables if you are running this script outside of ArcToolBox. | |
#the_gdb = r"C:\LocalData\sandbox\New File Geodatabase.gdb" | |
#out_xml = r"C:\LocalData\temp\remove_gp_history_xml" | |
## Make sure this variable value matches the path to your XSLT to remove geoprocessing history | |
remove_gp_history_xslt = r"C:\Program Files (x86)\ArcGIS\Desktop10.5\Metadata\Stylesheets\gpTools\remove geoprocessing history.xslt" | |
## DEFINE FUNCTIONS | |
# Define dual console logging output function | |
def tellUser( message="\n" ): | |
if message == "\n": | |
else: | |
print message | |
arcpy.AddMessage( message ) | |
# Define the Dataset Feature Class iterator function (all FC's inside of Datasets) | |
def RemoveGpHistory_fd(the_gdb,remove_gp_history_xslt,out_xml): | |
arcpy.ClearWorkspaceCache_management() | |
arcpy.env.workspace = the_gdb | |
for fd in arcpy.ListDatasets(): | |
arcpy.env.workspace = the_gdb + os.sep + fd | |
for fc in arcpy.ListFeatureClasses(): | |
name_xml = out_xml + os.sep + str(fc) + ".xml" | |
# Process: XSLT Transformation | |
arcpy.XSLTransform_conversion(the_gdb + os.sep + fd + os.sep + fc, remove_gp_history_xslt, name_xml, "") | |
tellUser("Completed xml coversion on FC \"{1}\" in dataset \"{0}\"".format(fd,fc)) | |
# Process: Metadata Importer | |
arcpy.MetadataImporter_conversion(name_xml,the_gdb + os.sep + fd + os.sep + fc) | |
tellUser("Imported XML on {0}".format(fc)) | |
tellUser("Geoprocessing History has been removed from {0}".format(fc)) | |
os.remove( name_xml ) | |
# Define the Root Feature Class iterator function (all FC's not in a dataset) | |
def RemoveGpHistory_fc(the_gdb,remove_gp_history_xslt,out_xml): | |
arcpy.ClearWorkspaceCache_management() | |
arcpy.env.workspace = the_gdb | |
for fx in arcpy.ListFeatureClasses(): | |
name_xml = out_xml + os.sep + str(fx) + ".xml" | |
# Process: XSLT Transformation | |
arcpy.XSLTransform_conversion(the_gdb + os.sep + fx, remove_gp_history_xslt, name_xml, "") | |
tellUser("Completed XML conversion on {0}".format(fx)) | |
# Process: Metadata Importer | |
arcpy.MetadataImporter_conversion(name_xml,the_gdb + os.sep + fx) | |
tellUser("Imported XML on {0}".format(fx)) | |
tellUser("Geoprocessing History has been removed from {0}".format(fx)) | |
os.remove( name_xml ) | |
## EXECUTE FUNCTIONS | |
if __name__== "__main__": | |
tellUser() | |
tellUser( "Removing Geoprocessing History from Metadata for all Feature Classes in \"{0}\"".format(arcpy.Describe(the_gdb).name) + "...\n") | |
# if the directory you input doesn't yet exist, then it will be created | |
if not os.path.exists(out_xml): | |
os.mkdir(out_xml) | |
# execute Dataset Feature Class iterator | |
RemoveGpHistory_fd(the_gdb,remove_gp_history_xslt,out_xml) | |
tellUser() | |
# execute Root Feature Class iterator | |
RemoveGpHistory_fc(the_gdb,remove_gp_history_xslt,out_xml) | |
tellUser() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment