Select to view content in your preferred language

ifieldedit.name to rename feature class field is not persistent

732
1
04-19-2010 07:51 AM
MikeTischler
Emerging Contributor
Hi,
I've got a featureclass that I'm trying to join ~50 tables to.  I built a model in model builder that relies on "Join Field" to do the joining.  But, I want to rename all the newly joined fields in the featureclass to different names.  So, I wrote a VBA script to do it.  I can rename the fields, but the changes do not persist.  By that, I mean that I can open the attribute table in ArcMap after I've run the script, and the field names are changed.  However, if I close ArcMap and reopen it, the field names revert to their original name.  Or, while ArcMap is still open after running the script, the table preview in ArcCatalog reflects no change.  I tried this with both a shapefile and a FGDB FeatureClass.

And, if I view the attribute table with the renamed fields and try to export it, the resulting table does *not* include the newly joined fields at all!

I did find a workaround.  Once I rename the fields using my script below, I use the geoprocessing tool "Copy Rows" to create a new table.  I can then build that back to a feature class by creating events based on X-Y coordinates also in the table.  But, I 'm still curious why IFieldEdit2.name won't make a permanent name change.

Here's what my code looks like for renaming one field.  I also did this in .NET by setting IFieldEdit.Name_2, but with the same results.

Public Sub go()
Dim pfc As IFeatureClass
Dim pmap As IMap
Dim pdoc As IMxDocument
Set pdoc = ThisDocument
Set pmap = pdoc.FocusMap
Dim pflayer As IFeatureLayer
Set pflayer = pmap.Layer(0)
Set pfc = pflayer.FeatureClass

Dim i As Integer
Dim layername As String

'this is what I want to rename the field to 

layername = "MyNewName"

Dim pfield As IField
Dim pfieldedit As IFieldEdit2
Dim lfld As Integer

'this is the original field name
lfld = pfc.FindField("NEAR_DIST")

Set pfield = pfc.Fields.Field(lfld)
Set pfieldedit = pfield
pfieldedit.Name = layername

End Sub
0 Kudos
1 Reply
StefanOffermann
Deactivated User
Field names can not be renamed. You can only rename the Alias name, which is only reflected in MXD-documents, not in ArcCatalog. The only workaround is to create a new field with the new name and copy all values to this field, eg using CalculateField tool. Afterwards you can delete the old field. This may take much time, depending on how much rows and fields you want to "rename".

Secondly, joins are only reflected in the MXD-document in ArcMap and are not visible in ArcCatalog. To make the join persistent, you can use the CopyRows tool, exactly as you've written. Another possibility is to use the JoinField tool (available at ArcInfo license level), which copies the field directly to the target table.

Best regards, Stefan
0 Kudos