English

How To: Delete geoprocessing history from a geodatabase in ArcMap using Python

Summary

Geoprocessing tools add metadata about its execution in a geodatabase. The metadata includes the tool name, its location, and the parameters used when geoprocessing logging is enabled. GIS administrators and managers sometimes need to delete the geoprocessing history from a feature class or workspace metadata.

The following script describes how to achieve this goal using a Python script and workflow of how to remove geoprocessing history from an enterprise geodatabase workspace.

Procedure

Remove geoprocessing history from feature classes

The instructions provided below describe how to achieve this goal using a Python script. The following script automates this process for all feature classes in a geodatabase, including feature classes stored in a feature dataset.

Note:
Perform the procedure in the 32-bit version of Python.

Run the included Python script after updating the variables:

import arcpy
import os, string

''' Update the following five variables before running the script.'''
version = "10.5"
myWorkspace = r"C:\XML_out\dbinstance_testgdb.sde"
gp_history_xslt = r"C:\Program Files (x86)\ArcGIS\Desktop{}\Metadata\Stylesheets\gpTools\remove geoprocessing history.xslt".format(version)
output_dir = r"C:\XML_out"
db_type = "SQL" #Set this to either "SQL" or "Oracle" if your db has spatial views. If not you may set it to "".

def RemoveHistory(myWorkspace, gp_history_xslt, output_dir):
##Removes GP History for feature dataset stored feature classes, and feature classes in the File Geodatabase.

    arcpy.env.workspace = myWorkspace
    for fds in arcpy.ListDatasets('','feature') + ['']:
        for fc in arcpy.ListFeatureClasses('','',fds):
            data_path = os.path.join(myWorkspace, fds, fc)
            if isNotSpatialView(myWorkspace, fc):
                removeAll(data_path, fc, gp_history_xslt, output_dir)


def isNotSpatialView(myWorkspace, fc):
##Determines if the item is a spatial view and if so returns True to listFcsInGDB()    
    if db_type <> "":
        desc = arcpy.Describe(fc)
        fcName = desc.name
        #Connect to the GDB
        egdb_conn = arcpy.ArcSDESQLExecute(myWorkspace)
        #Execute SQL against the view table for the specified RDBMS
        if db_type == "SQL":
            db, schema, tableName = fcName.split(".")
            sql = r"IF EXISTS(select * FROM sys.views where name = '{0}') SELECT 1 ELSE SELECT 0".format(tableName)
        elif db_type == "Oracle":
            schema, tableName = fcName.split(".")
            sql = r"SELECT count(*) from dual where exists (select * from user_views where view_name = '{0}')".format(tableName)
            egdb_return = egdb_conn.execute(sql)
            if egdb_return == 0:
                return True
            else:
                return False
        else: return True
    else: return True

def removeAll(data_path, feature, gp_history_xslt, output_dir):
##Remove all GP History metadata from a feature class.

    arcpy.ClearWorkspaceCache_management()
    name_xml = os.path.join(output_dir, str(feature)) + ".xml"

    arcpy.XSLTransform_conversion(data_path, gp_history_xslt, name_xml)
    print "Completed xml coversion on {0}".format(feature)

    arcpy.MetadataImporter_conversion(name_xml, data_path)
    print "Imported XML on {0}".format(feature)

def makeDirectory(output_dir):
##Creates directory to store the xml tables of converted metadata. If the
##directory already exists, the files will be created there.

    if not arcpy.Exists(output_dir):
        os.mkdir(output_dir)

if __name__ == "__main__":
    makeDirectory(output_dir)
    RemoveHistory(myWorkspace, gp_history_xslt, output_dir)
print "Done Done"

Remove geoprocessing history from an enterprise geodatabase workspace

  1. Connect to an enterprise geodatabase as the geodatabase administrator.
  2. Run the XSLT Transformation geoprocessing tool to generate an .xml from the database with the geoprocessing history removed.
    • Source Metadata: The database connection
    • Input XSLT: The Esri tool located at:
C:\Program Files (x86)\ArcGIS\Desktop10.5\Metadata\Stylesheets\gpTools\remove geoprocessing history.xslt
  • Output File: Provide a location to save the output .xml file
The XSLT Transformation tool window with the appropriate parameters filled.
  1. Run the Metadata Importer geoprocessing tool to import the output .xml file into the enterprise geodatabase.
    • Source Metadata: The output .xml generated from Step 2
    • Target Metadata: The database connection
The Metadata Importer tool window with the appropriate parameters filled

Related Information

Last Published: 8/16/2021

Article ID: 000011751

Software: ArcGIS for Desktop Advanced 10.3.1, 10.3, 10.2.2, 10.2.1, 10.2, 10.1 ArcGIS for Desktop Basic 10.3.1, 10.3, 10.2.2, 10.2.1, 10.2, 10.1 ArcGIS for Desktop Standard 10.3.1, 10.3, 10.2.2, 10.2.1, 10.2, 10.1