Read Field Alias from mxd in arcpy

427
2
04-21-2020 06:29 AM
LukasWürsch
New Contributor III

Hi,

I noticed that the field alias name, which is shown in the attribute table of ArcMap, does not correspond with the field alias name accessible in arcpy. 

For example, when "manually" changing the field alias name in the .mxd's attribute table, the alias in arcpy does not change. (accessed alias in arcpy like this)

for field in arcpy.ListFields('<Featureclass>'):
     print field.aliasName

Is there a way to read the alias name with arcpy (the one created manually, which is saved in the mxd) ?

The reason for the question is that I work with a large amount of layers whose field alias names were modified manually in mxds and i need to access those aliases in arcpy. So I am looking for an automated way to read the aliases from the attribute table and then overwrite the actual field aliases with arcpy (using arcpy.management.AlterField).

I would highly appreciate any help or hints.

 

0 Kudos
2 Replies
DanPatterson_Retired
MVP Esteemed Contributor

Don't know about arcmap, but in Pro this tools can be used

Alter Field—Data Management toolbox | Documentation 

Direct arcpy changes I think depend on whether are looking at the layer/table view level or the actual featureclass.

Some reading, or just skip to the last comment

Using fields and indexes—ArcPy Get Started | Documentation 

You can read the alias, but in order to change it either the table needs to be empty or the field depending on what you want to change

Alter Field—Data Management toolbox | Documentation 

It may be due to the differences between what can be seen or changed at the layer level versus the featureclass level

based on this comments scattered throughout the help files

The data source view displays field properties that are at the feature class level, such as the alias for a field, or the field name.

and

Updating a field property only updates the field object, no changes are made to the actual field in the table or feature class.

In any event, If you can use the AlterField_Management tool in your script, be careful on how you set the parameters

cannot change field alias without changing field name 

LukasWürsch
New Contributor III

Hi Dan,

Thank you for the calcification regarding the alter field tool. I can read the alias as described here, but then i get the alias of the feature class, not the one in the mxd i think. What I am looking for is a way to read the alias saved in the mxd, not in the feature class. But maybe that is not possible with arcpy. Thank you for the help anyways.

0 Kudos