Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

Cheers

Halil

share

2 Answers 2

up vote 1 down vote accepted

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.

share
    
I saw that page but must have missed it. –  Halil Siddique Jun 20 '12 at 8:22

As Get Spatial said the Layer object does not seem able to get at the field aliases but if you use the Field class with ListFields or Describe then that looks like it does provide access to them.

share
    
This is the alias on the FC from SDE not from the map document. Thanks anyways. –  Halil Siddique Jun 20 '12 at 8:22
    
I forgot to read the documentation on types of field aliases at help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//… before I responded. I'll be happy to vote for any ArcGIS Idea that asks for what you need here. –  PolyGeo Jun 20 '12 at 9:40

This site is currently not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .