import arcpy from arcpy import env import os, zipfile, zlib, shutil mxd = arcpy.mapping.MapDocument(r"C:\\temp\OpenData\OpenData_test.mxd") for lyr in arcpy.mapping.ListLayers(mxd): desc = arcpy.Describe(lyr) for field in desc.fields: print field.name, ":", field.aliasName, ":", field.type, ":", field.length, ":", field.domain del mxd
fields = arcpy.ListFields(lyr) for field in fields: print("Field: {0}".format(field.name)) print("Alias: {0}".format(field.aliasName))
>>> mxd = arcpy.mapping.MapDocument('CURRENT') >>> lyr = arcpy.mapping.ListLayers(mxd, 'testAlias') >>> len(lyr) 1 >>> fields = arcpy.ListFields(lyr[0]) >>> len(fields) 5 >>> for field in fields: ... print('Field: {0}'.format(field.name)) ... print('Alias: {0}\n'.format(field.aliasName)) ... Field: OBJECTID Alias: OBJECTID Field: SHAPE Alias: SHAPE Field: testfld Alias: testAlias Field: SHAPE_Length Alias: SHAPE_Length Field: SHAPE_Area Alias: SHAPE_Area >>>
mxd = arcpy.mapping.MapDocument('CURRENT') lyr = arcpy.mapping.ListLayers(mxd) for lyr in arcpy.mapping.ListLayers(mxd): if not lyr.isGroupLayer: print lyr.name fieldList = arcpy.ListFields(lyr) for field in fieldList: print(field.name + ": " + field.aliasName + ": " + field.type) del mxd
I have 10.0 SP 5 installed on one of my machines and wanted to test that out - it works fine (see the Python 'live' coding within ArcMap below - I did not test stand-alone). I added an alias, testAlias, to a dummy field, testfld, in a fc added to the map, a layer called 'testAlias' (sorry didn't mean to redundantly name it the same as my field alias - so don't be confused about that).>>> mxd = arcpy.mapping.MapDocument('CURRENT') >>> lyr = arcpy.mapping.ListLayers(mxd, 'testAlias') >>> len(lyr) 1 >>> fields = arcpy.ListFields(lyr[0]) >>> len(fields) 5 >>> for field in fields: ... print('Field: {0}'.format(field.name)) ... print('Alias: {0}\n'.format(field.aliasName)) ... Field: OBJECTID Alias: OBJECTID Field: SHAPE Alias: SHAPE Field: testfld Alias: testAlias Field: SHAPE_Length Alias: SHAPE_Length Field: SHAPE_Area Alias: SHAPE_Area >>>
So feeding in a layer obj from the map to ListFields works (ignore my warning in the last post).
Also, it appears you'll get an original field name as the field alias where no alias has been set.