Hello.
I have created a custom ArcGIS tool, and need to automate this tool so that it can be scheduled to run weekly outside of ArcMap.
Right now, I have a version of the tool that runs inside of an ArcMap session, with the input table and target feature class as user defined parameters.
Here is the code that I have so far.
My Try/Except block is commented out for testing purposes.
The goal is that the script will join an SDE view table to a GDB feature class, select based on some criteria, calculate some fields, than remove the join. Works great as a tool, but getting it to work outside of that has proven impossible so far.
Thanks for any help!
import arcpy, sys, string, os, subprocess
gca = vca = "Conservation_Area_Name"
gcn = vcn = "Conservation_Area_Number"
gn = vn = "Network"
gfi = "Field_ID"
gai = "Asset_ID"
gt1n = "Tier_1_System_Name"
gt1t = "Tier_1_System_Type"
gt2n = "Tier_2_Major_Subsystem_Name"
gt2t = "Tier_2_Major_Subsystem_Type"
gt3n = "Tier_3_Minor_Subsystem_Name"
gt3t = "Tier_3_Minor_Subsystem_Type"
gt4n = "Asset_Name"
vfi = "FieldID"
vai = "AssetID"
vt1n = "Tier_1_Name"
vt1t = "Tier_1_Type"
vt2n = "Tier_2_Name"
vt2t = "Tier_2_Type"
vt3n = "Tier_3_Name"
vt3t = "Tier_3_Type"
vt4n = "Tier_4_Name"
gdfcin = r'C:\Projects\MDC\DataUpdate_20180315\MDC_PhysModel_FieldID_20180315.gdb\Exterior_Electrical\Phase_Converter_Exterior'
gdfc = gdfcin.split('\\')[-1]
vwfcin = r'C:\Users\rbasaria\AppData\Roaming\ESRI\Desktop10.4\ArcCatalog\MDCTest_1025.sde\MDCTest_1025.dbo.ViewETL_FacilityType_PhaseConverterExterior'
vwfc = vwfcin.split('\\')[-1]
slct = gdfc+"."+gai+" IS NULL OR ("+gdfc+"."+gai+" <> "+vwfc+"."+vai+")"
arcpy.AddJoin_management(gdfcin, gfi, vwfcin, vfi)
arcpy.SelectLayerByAttribute_management(gdfcin, "NEW_SELECTION", slct)
arcpy.CalculateField_management(gdfcin, gdfc+"."+gai, "["+vwfc+"."+vai+"]", "VB", "")
arcpy.CalculateField_management(gdfcin, gdfc+"."+gca, "["+vwfc+"."+vca+"]", "VB", "")
arcpy.CalculateField_management(gdfcin, gdfc+"."+gcn, "["+vwfc+"."+vcn+"]", "VB", "")
arcpy.CalculateField_management(gdfcin, gdfc+"."+gn, "["+vwfc+"."+vn+"]", "VB", "")
arcpy.CalculateField_management(gdfcin, gdfc+"."+gt1n, "["+vwfc+"."+vt1n+"]", "VB", "")
arcpy.CalculateField_management(gdfcin, gdfc+"."+gt1t, "["+vwfc+"."+vt1t+"]", "VB", "")
arcpy.CalculateField_management(gdfcin, gdfc+"."+gt2n, "["+vwfc+"."+vt2n+"]", "VB", "")
arcpy.CalculateField_management(gdfcin, gdfc+"."+gt2t, "["+vwfc+"."+vt2t+"]", "VB", "")
arcpy.CalculateField_management(gdfcin, gdfc+"."+gt3n, "["+vwfc+"."+vt3n+"]", "VB", "")
arcpy.CalculateField_management(gdfcin, gdfc+"."+gt3t, "["+vwfc+"."+vt3t+"]", "VB", "")
arcpy.CalculateField_management(gdfcin, gdfc+"."+gt4n, "["+vwfc+"."+vt4n+"]", "VB", "")
arcpy.RemoveJoin_management(gdfcin)
arcpy.SelectLayerByAttribute_management(gdfcin, "CLEAR_SELECTION", "")