[GIS] Getting the Field Alias from a layer, from within a Map document

aliasarcgis-10.0arcpy

I've got a very simple script, that loops through all the layers in a mxd and loops through the fields, and prints out the Alias Name for the field, but I am having some problems, it seems to be printing the field alias of the feature class (in SDE) not the value I have changed it to in the map document…

Here's the script

import os, arcpy

myMxdFolder = r"D:\Maps"
count = 0

for mxd in os.listdir(myMxdFolder):
    #print mxd
    if mxd.endswith(".mxd"):
        #if mxd.startswith("COMPASS") or mxd.startswith("COLGIS"):
        if mxd.startswith("COLGIS_City_Occupiers.mxd"):
            mxdoc = arcpy.mapping.MapDocument(myMxdFolder + os.sep + mxd)
            filePath =  mxdoc.filePath
            print filePath
            for lyr in arcpy.mapping.ListLayers(mxdoc):
                desc = arcpy.Describe(lyr)
                print lyr.name
                fields = desc.fields
                for field in fields:
                    print field.aliasName

The output is

OBJECTID
UPRN
ADDRESS
OCCUPIER
SHAPE

but the Aliases in the map document i have set it to are:

OBJECTID
HIGHLIGHT::UPRN
Address
Occupier
SHAPE

and that is what I was expecting, have a missed a trick somewhere in the code?

Best Answer

Unfortunately, I think your answer can be found from this excerpt from this ESRI Help Document on Layer

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 (e.g., scale ranges, display properties, field aliases, symbology, and so on). The UpdateLayer function allows you to replace all layer properties available in ArcMap's Layer Properties dialog box using a layer (.lyr) file that contains the customizations.

It specifically references field aliases and the Layer Properties dialog.

This might be something worth submitting an idea to the ArcGIS Ideas site.