I am experiencing a strange issue, not all the feature classes have been updated when running the following python script in ModelBuilder
The filegeodatabase has a total of 9 feature classes (six of the feature classes have been updated and three are not), no errors are shown in ModelBuilder.
Here is the script I am running:
# Import system modules
import arcpy, os
from arcpy import env
#Set the workspace so that Python knows where to look for the feature classes.
# In this case, it is a GDB
arcpy.env.workspace = r'D:/spatial_data/parcel_data/scratchdb.gdb'
# list the feature classes
fcList = arcpy.ListFeatureClasses()
# loop through list
for fc in fcList:
#check if field exists, if not, add it and calculate
if "RegCode" not in arcpy.ListFields (fc):
arcpy.AddField_management(fc, "RegCode", "TEXT", "", "", field_length = 😎
if "IdCode" not in arcpy.ListFields (fc):
arcpy.AddField_management(fc, "IdCode", "TEXT", "", "", field_length = 😎
if "PNoCreate" not in arcpy.ListFields (fc):
arcpy.AddField_management(fc, "PNoCreate", "TEXT", "", "", field_length = 😎
if "PnNoCreate" not in arcpy.ListFields (fc):
arcpy.AddField_management(fc, "PnNoCreate", "TEXT", "", "", field_length = 5)
if "IdCreate" not in arcpy.ListFields (fc):
arcpy.AddField_management(fc, "IdCreate", "TEXT", "", "", field_length = 21)
which begs the question... which ones and which field(s) didn't get updated? could it be that a few aren't featureclasses but tables?
to save a download and inspect, did you consider placin a print statement after the listfeature classes to see what was listed and perhaps a print statement after you get a list of the field names to compare to a list of field names as in example 2 in the help topic
I added - arcpy.SetLogHistory(True)
# Import system modules
import arcpy, os
from arcpy import env
arcpy.SetLogHistory(True)
...
The script is running as expected for all feature classes - all the fields are added.
As to why the script was not executing as expected, I am still not sure of what the problem is.
Thanks Dan for some pointers.
glad to hear it worked out