Arcpy Add Field issue _ Allies Not showing in table

712
1
06-04-2012 03:43 PM
BruceGreen
New Contributor III
Hi,
Using ArcMap 10 I am trying to add two fields to a shapefile from a standalone Arcpy.the field has been added to the future class after ruing the code BUT:- The field_alias does not show up at the table of the future class even after I manually checked the "Display Field Aliases" from "Layer Properties--> Fields--> Options"

# Import arcpy module
import arcpy

# Local variables:
fshape = "C:\\Temp\\test.shp"

try:
    # Process: Add Field
    # AddField_management (in_table, field_name, field_type, {field_precision}, {field_scale}, {field_length}, {field_alias}, {field_is_nullable}, {field_is_required}, {field_domain})
    arcpy.AddField_management(fshape, "Area", "DOUBLE", "2", "", "", "This is not Real Name", "NON_NULLABLE", "NON_REQUIRED", "")
    print ("Fields has been Added")
except Exception as e:
    print( e.message)


Can you please let me know what I am doing wrong?

thanks
Tags (2)
0 Kudos
1 Reply
MarcinGasior
Occasional Contributor III
Due to web help on Add Field (Data Management) (sixth bullet):
"A shapefile does not support alias for fields, so you cannot add a field alias to a shapefile."

You can change alias for shapefile in Layer Properties, but it's not preserved with shapefile.
If you really need aliases, migrate to geodatabase.
0 Kudos