2

I need to add multiple fields to multiple feature classes and I'm having problems with the domains (the predetermined options of certain fields). In the example below, it'd be the word 'Status' in the fourth line. I can't get ArcGIS Pro to associate the existing domain in the geodatabase to the new field.

import arcpy

arcpy.env.workspace = "Projects.gdb"

feature_class = "City_State"

fields = [('NewID', 'SHORT'), ('Status', 'TEXT', 'Status', 255, '', 'Status')]

for field in fields:
    arcpy.management.AddField(feature_class, field[0], field[1])

1 Answer 1

1

You are only adding two variables to the AddField command. You need to make use of the other variables.

fields = [('NewID', 'SHORT'), ('Status', 'TEXT', 'Status', 255, '', 'Status')]

for field in fields:
    if len(field)==2:
        arcpy.management.AddField(feature_class, field[0], field[1])
    elif len(field)==6:
        arcpy.management.AddField(feature_class, field[0], field[1], field_length=field[3], field_domain=field[5])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.