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


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


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

1 Answer 1


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.