Change fields alias  in layer within mxd?

8374
20
09-03-2012 05:10 AM
BartłomiejStaroń
New Contributor III
It is possible to change fields alias  in layer within mxd by arcpy?(Table Options > Appearance)
Tags (2)
20 Replies
KevinYanuk
Occasional Contributor
It is possible to change fields alias  in layer within mxd by arcpy?(Table Options > Appearance)


Have you taken a look at this:


http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000071000000
0 Kudos
ChristopherThompson
Occasional Contributor III
It looks like you can get and set the alias name within the scripting environment but I've been unable to actually make that change show up anywhere else.  This statement in the help about field objects leads me to believe that you cannot actually change the alias in the resource on disk:
Updating a field property only updates the field object, no changes are made to the actual field in the table or feature class.
0 Kudos
JeffBarrette
Esri Regular Contributor
You may want to give arcpy.mapping.UpdateLayer() a try.
http://resources.arcgis.com/en/help/main/10.1/#/UpdateLayer/00s30000003p000000/

This will only work well for you if you have the same layer multiple times in the same MXD or many MXDs.  The reason being is that you must first create a layer file with ALL the correct layer properties, including your field aliases.  So edit one of them and save it to a layer file. Then you write a script to find all the layers and update them using your authored layer file.

Because you want to update ALL properties, set symbology_only=False.  When set to false, ALL properties, including the data source will get overwritten.

I hope this helps,
Jeff
0 Kudos
TysonSchoepflin
New Contributor II
Updating a field property only updates the field object, no changes are made to the actual field in the table or feature class.


Well, I've spent too many hours trying to solve this issue.  It appears you cannot change the field alias for a field within the mxd file and save it back to the mxd file.  The alias name in the mxd file is independent of the data source once set.

When a geodatabase feature class is added to ArcMap, its field aliases are used initially for the layer field aliases. However, after this there is no link between the two. Properties set in ArcMap will override the properties of the data source, but they will not be carried back to the data source. This means that if you change a layer field alias, it will not change the feature class field alias, and if you change a geodatabase field alias, it will not update the layer field alias for any existing layers based on the feature class.


It is completely frustrating that the mxd field alias cannot be changed using python.
Jose_FrancisK_J
New Contributor

Have you found any other method to update the field alias in an mxd layer ?

Our SDE contains the updated alias but not able to update in mxd.

Well, I've spent too many hours trying to solve this issue.

How you solved your issue.

0 Kudos
JulianInskip
Occasional Contributor

For what it is worth now, I kind of found a way to indirectly do this. Although it is not directly altering the field alias in the MXD, this way does seem to work. I create a data inventory of my feature classes in the gdb in a csv file. I then update all my aliases and stuff in the csv. I then run my next script that uses the AlterField tool to make the changed in my csv file to my feature classes.

All pretty standard and non-mxd(ish) up until now.

From here, I made use of T. Wayne Whitley reply from this thread which actually goes through to update the field visibility setting for the relevant layers using fieldInfo. Once the new layer is added/updated, the feature classes field alias seems to be updated also. I then use mxd.saveACopy to make a new output mxd.

Hope this helps.

Julian

MitchHolley1
MVP Regular Contributor
0 Kudos
Jose_FrancisK_J
New Contributor

Alter Field tool is to rename fields or field aliases for any feature class. I've already updated alias name in feature class. Since MXD layers have separate field mappings, the alias from the SDE fields are not reflecting in MXD layer. Hence thought of reading the layers from mxd and update the field alias.

As Jeff Barrette said, I've tried the UpdateLayer method. This has to be executed with the flag symbology_only=False for updating the fields. When I executed this, I lost the symbology.

0 Kudos
Rhys-Donoghue
New Contributor III

This can be done like this (all arcpy, except step 2):

1) Use arcpy.ListFields() to get field names and field aliases from a feature class, and output to a csv file

2) In the csv file, update the alias column

3) Using arcpy, re-add the feature class to the map document (mxd) - it will have the wrong symbology

4) Use arcpy.ApplySymbologyFromLayer_management() to update the symbology

5) Use arcpy to delete the original layer from the MXD

Just be aware that ApplySymbologyFromLayer_management may not bring across all layer properties, e.g. Definition Queries.

0 Kudos