Select to view content in your preferred language

Is Modelbuilder the *only* way to rename fields - not succeeding in Python

640
4
Jump to solution
11-01-2012 05:04 PM
HarryBowman
Deactivated User
Probably doing it incorrectly, but following the samples in which I try Python:

import arcpy fi = arcpy.FieldInfo() fi.addField("Name", "Name2", "VISIBLE", "") arcpy.MakeFeatureLayer_management("TheFC, "foo5", "","", fi) arcpy.CopyFeatures_management("foo5", "hoo1")


Does NOT persist renaming the fields. Hoo1 still has the old names. According to what I have read, it shouldn't. Is modelbuilder the *only* way renaming works? Is it possible by using ArcPy field methods? What am I doing incorrectly (this time)?
0 Kudos
1 Solution

Accepted Solutions
MarcinGasior
Frequent Contributor
Harry's script works ok for me. I suppose it's based on example from this page where creating FieldInfo object directly from arcpy is used.

At first glance, it seemed for me that field name was not changed. But I checked feature class properties and it turned out that actually field name was changed but not a field alias which is used in display in Attribute table.
So check actuall field name in feature class properties.

View solution in original post

0 Kudos
4 Replies
DuncanHornby
MVP Notable Contributor
Harry,

Are you showing the complete code in your uploaded sample? If you search the Help file for FieldInfo the example given in the help shows that this object is obtained via the Describe Object.  Maybe your fieldInfo object is invalid?

Duncan
0 Kudos
MarcinGasior
Frequent Contributor
Harry's script works ok for me. I suppose it's based on example from this page where creating FieldInfo object directly from arcpy is used.

At first glance, it seemed for me that field name was not changed. But I checked feature class properties and it turned out that actually field name was changed but not a field alias which is used in display in Attribute table.
So check actuall field name in feature class properties.
0 Kudos
HarryBowman
Deactivated User
You are exactly correct - in Catalog, you can see that the field is the correct name. Now I just need to figure out how to change the alias, since that is what the user will see.
0 Kudos
JohnHansen
Occasional Contributor
Harry -

Did you ever figure out a way to change the alias name via arcpy?

Thx

John
0 Kudos