Batch Add Fields, Model Builder

8523
11
Jump to solution
02-09-2015 07:00 AM
Randy_A_Stapleton
New Contributor III

Hi All,

 

Can anyone suggest a better way to batch add fields using the model builder? See attached image.

 

 

Thanks,

11 Replies
Randy_A_Stapleton
New Contributor III

This shows that 4 additional field were created. Batch_AddField_03.PNG

0 Kudos
BlakeTerhune
MVP Regular Contributor

My first thought is to use Python and arcpy.AddField_management(). This assumes all the fields are the same type and length. If they are all different, it can still be done but the code would have to be changed a bit.

import arcpy

testtable = r"C:\temp\mygdb.gdb\Test"

newfields = [
    "Test1",
    "Test2",
    "Test3",
    "Test4",
    "Test5"
]

for field in newfields:
    arcpy.AddField_management(
        testtable,  ## in_table
        field,  ## field_name
        "TEXT",  ## field_type
    )
    print "{} added".format(field)