Not all feature classes updated with Python script

1576
5
05-03-2016 01:16 PM
MaziziJama
New Contributor

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.

Capture.PNG

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)

Tags (2)
0 Kudos
5 Replies
DanPatterson_Retired
MVP Esteemed Contributor

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?

0 Kudos
MaziziJama
New Contributor

All of them are feature classes.

I am using the script to add multiple fields using the python script.

I have also attached a sample filegeodatabase.

I am only able to add the fields to the Farm_Portion feature class.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

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

ListFields—Help | ArcGIS for Desktop

0 Kudos
MaziziJama
New Contributor

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.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

glad to hear it worked out

0 Kudos