Hi -
Am trying to add a field to multiple classes in a File Geodatabase in ArcCatalog with a python script (below.) The script periodically errors on AddField_management returning a "General Function Failure". After the error I can't open the class and receive a "Can't edit object(s)" message box.
I've made sure that all classes are OK (can be opened and inspected) prior to running the script. So, I'm pretty sure there is something about the script that is causing a problem.
At first I though it might be the number of items in the class name list -- it seemed to fail on processing the 20th item. But now I'm not so sure.
Any insights on this would be greatly appreciated.
Thanks,
Ed
import arcpy
#Set the connection information
arcpy.env.workspace = "C:\Projects\Pilot_Test.gdb"
def FieldExist(featureclass, fieldname😞
fieldList = arcpy.ListFields(featureclass, fieldname)
fieldCount = len(fieldList)
if (fieldCount == 1😞
return True
else:
return False
try:
########################################################################
# Field properties for all new fields
########################################################################
fieldName = "FACILITYID"
aliasName = "Facility ID"
fieldType = "TEXT"
fieldLength = 20
########################################################################
# Iterate over classes
########################################################################
print("Add FACILITYID to classes")
classNames = ["cwFieldRestraint", "cwFitting", "cwPipe","AbandonedCurbBox","AbandonedWaterFitting",\
"AbandonedWaterMain","AbandonedWaterService",\
"AbandonedUGSecondary","AnchorGuy","BusBar","FaultCurrentZoneLimit",\
"FixedConsService","XY","PriOHElectricLineSegment","SecOHElectricLineSegment",\
"SecUGElectricLineSegment","ServicePoint","SpanGuy","Streetlight","Substation",\
"Transformer","TransmissionLine",\
"wCasing","wFitting","wCurbBox","wFieldRestraint","wMainTap","wMaintenanceTap",\
"wOffset","wPumpOut","wRawCasing","wRawFitting","wRawMain","wServicePoint",\
"wSludgeCasing","wSludgeFitting","wSludgeMain","wMain","wMeter","wService"]
for c in classNames:
if (not FieldExist(c, fieldName)):
arcpy.AddField_management(c, fieldName, fieldType, "", "", fieldLength, aliasName, "NULLABLE")
else:
print "Field " + fieldName + " already exists in class " + c
print("Fields added successfully")
print("Process completed")
except:
#If an error occurs when running Addfield, print out the error message.
print(arcpy.GetMessages())