[GIS] Updating field aliases for ArcGIS map document layer using ArcPy

aliasarcpyfields-attributeslayers

I am on ArcGIS 10.4.1.

I have an .mxd file with a bunch of layers. The underlying database table has got new aliases for certain fields and I would like to get this reflected in the fields aliases for the corresponding layers.

  • If I remove the layer and add the feature class, I have to re-set the symbology + all other layer properties such as scale ranges, labels etc.

  • If I save the .lyr file first and re-apply it using arcpy.mapping.UpdateLayer, I will get back all the symbology, but also the field aliases which I don't want.

  • If I set the symbology_only=True, I will need to re-set all other properties manually.

I have seen the ArcObjects code and am able to update it using comtypes and C# code, however I wonder whether there is a way to update the layer's field aliases using arcpy.

I have seen that ArcMap X-Ray add-in has functionality of updating field aliases for the map document layers, great one. However, this should be done for every map document manually, thus it's impossible to script.

Best Answer

In the ArcGIS Desktop help page for Layer it specifically says you can't update field aliases using arcpy

Not all layer properties are accessible through the Layer object. There are many properties available in the ArcMap Layer Properties dialog box that are not exposed to the arcpy scripting environment (for example, display properties, field aliases, selection symbology, and so on). The UpdateLayer function allows you to replace all layer properties available in the ArcMap Layer Properties dialog box using a layer (.lyr) file that contains the customizations.

(emphasis added by me)

I cannot find the matching info in the ArcGIS Pro Layer page, however I also don't see any way to do it in Pro either.

Related Question