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

466
4
Jump to solution
11-01-2012 05:04 PM
HarryBowman
New Contributor III
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
Occasional Contributor III
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
Occasional Contributor III
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
New Contributor III
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
New Contributor III
Harry -

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

Thx

John
0 Kudos