Index Value parameter for arcpy.AddField_management() function/Create Field tool

Idea created by johnmdye on Aug 21, 2014
    • Hornbydd
    • johnmdye
    ArcGIS needs the ability to add a new field to a specific place within an existing table. Currently, all new fields added to a table are appended to the end of the table. It would be a nice enhancement to able able to provide an index value to the AddField_management function which would be used to determine the location within the table at which the new field should be inserted. In the case of the standard ArcToolbox-based Create Field tool, you could accomplish this by allowing the user to select a 'Before/After' parameter followed by a Field Name from a list, then from those two parameter values determine the index value at which the new field should be created)

    AddField_management (in_table, field_name, field_type, {field_index}, {field_precision}, {field_scale},
                                       {field_length}, {field_alias}, {field_is_nullable}, {field_is_required}, {field_domain})

    # Import system modulesimportarcpyfromarcpyimportenv# Set environment settingsenv.workspace="C:/data/airport.gdb"# Set local variablesinFeatures="schools"fieldName1="ref_ID"
    fieldIndex = 3
    fieldPrecision=9fieldAlias="refcode"fieldName2="status"fieldLength=10# Execute AddField function passing in an index value of '3' to add the
    # new field 'ref_ID' as the fourth field in the attribute tablearcpy.AddField_management(inFeatures,fieldName1,"LONG", fieldIndex, 
                              fieldPrecision,"","", fieldAlias,"NULLABLE")