Create a script that loops through table compare tool

03-28-2022 09:41 PM
New Contributor

I have started this script:

import arcpy
import os
import sys
from arcpy import env

# Set workspaces
WorkspaceNewGDB = r"C:\GIS6340\Final_Project_GIS6340\FC_03132022\NewFC2\New File Geodatabase.gdb"
ProjectWorkspace = r"C:\GIS6340\Final_Project_2\Final_Project_2.gdb"
MainGDB = r"C:\GIS6340\Geospatial_Library\ToDateFeatureClasses.gdb"
ClippedGDB = r"C:\GIS6340\Final_Project_GIS6340\FC_03132022\ClippedFC\ClippedGDB.gdb"

# Create new GDB for newly clipped layers
out_folder_path = r"C:\GIS6340\Final_Project_GIS6340\FC_03132022\ClippedFC"
out_gdb_name = "ClippedGDB", out_gdb_name)

# Clip new downloaded layers
clipFeature = r"C:\GIS6340\Final_Project_2\Final_Project_2.gdb\ANF_AdministrativeRegion"

env.workspace = WorkspaceNewGDB

# Loop through new feature classes and add to ClippedGDB
fcList = arcpy.ListFeatureClasses()

for fc in fcList:
out_ClipFC = ClippedGDB + "\\ANF_" + fc
arcpy.analysis.Clip(fc, clipFeature, out_ClipFC)

# Compare feature class from NewGBD to ProjectGDB
clippedGDBfcList = ("ANF_AdministrativeRegion", "ANF_Bld_FS_Office_Location", "ANF_RangerDistrict", "ANF_RightOfWay", "ANF_Road_MVUM", "ANF_RoadCore_FS", "ANF_RoadlessArea_2001", "ANF_SurfaceOwnership", "ANF_WatershedConditionClass")
projectfcList = ("ANF_AdministrativeRegion", "ANF_RangerDistrict", "ANF_RightOfWay", "ANF_Road_MVUM", "ANF_SurfaceOwnership", "ANF_WatershedConditionClass")

listDifference = (set(clippedGDBfcList) - set(projectfcList))

for clippedGDBfcList in clippedGDBfcList:
if clippedGDBfcList == projectfcList:
clippedGDBfcList = ["ANF_AdministrativeRegion", "ANF_Bld_FS_Office_Location", "ANF_RangerDistrict", "ANF_RightOfWay", "ANF_Road_MVUM", "ANF_RoadCore_FS", "ANF_RoadlessArea_2001", "ANF_SurfaceOwnership", "ANF_WatershedConditionClass"]
projectfcList = ["ANF_AdministrativeRegion", "ANF_RangerDistrict", "ANF_RightOfWay", "ANF_Road_MVUM", "ANF_SurfaceOwnership", "ANF_WatershedConditionClass"]

listDifference = (set(clippedGDBfcList) - set(projectfcList))

# Extract different layers and add them to MainGDB
listDifference = ("ANF_Bld_FS_Office_Location", "ANF_RoadCore_FS", "ANF_RoadlessArea_2001") # If list difference is printed from step above, insert
arcpy.conversion.FeatureClassToGeodatabase(listDifference, MainGDB)

# Delete listDifference feature classes from ClippedGDB

env.workspace = ClippedGDB
for fc in arcpy.ListFeatureClasses():

# Compare clippedGDB feature class table to ProjectGDB feature class tables


So everything is clipped, moved, deleted, and in the locations that they need to be. The last thing I want to do is compare the tables for each feature class, from clippedGDB compare to Final_Project2GDB' so ANF_AdministrativeRegion = ANF_AdminstrativeRegion, TRUE or FALSE. If it's TRUE nothing needs to be done, however if it is FALSE, then the feature class from clippedGDB needs to replace the corresponding feature class located in the MainGDB.  I have been trying to run the Table Compare tool in ArcGIS Pro, but as a python script, and just can't get it.

The path for ClippedGDB.gdb is:




The path for Final_Project is:



The path for MainGDB:




Per the table compare tool, the in_base_table is the correct data, which in this case its the Clipped GDB feature classes, and the in_test_table is the ProjectGDB feature classes.

I can run it individually through Pro:



which is correct. What I am trying to do is create a script that iterates through each feature class from each geodatabase and print out the name if there are changes.

I've tried but can't get it to work. If anyone can help, I'd appreciate it.


Tags (2)
0 Kudos
1 Reply
Esri Regular Contributor


You could call the same Table Compare tool from python code. 

After you run Table Compare geoprocessing tool from ArcGIS Pro click Open history. Right click on Table Compare item and choose "Copy Python Command" and paste it to your code. Change input parameters depending on your code.


More info here: 

List of tables you could get using arcpy.ListTables()


0 Kudos