Skip to content

Instantly share code, notes, and snippets.

@cindygis
Last active August 29, 2015 14:17
Show Gist options
  • Save cindygis/f7e0a66d8363f2172210 to your computer and use it in GitHub Desktop.
Save cindygis/f7e0a66d8363f2172210 to your computer and use it in GitHub Desktop.
Set the label expression and switch on labels for all layers in an ArcMap document.
#
# @date 17/09/2014
# @author Cindy Williams
#
# Set the label field and switch labels on for
# all layers in a mxd.
#
# For use in the Python window in ArcMap.
#
import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.isFeatureLayer:
f = arcpy.ListFields(lyr, "*GIS*")
if f:
lyr.labelClasses[0].expression = "[" + f[0].name + "]"
lyr.showLabels = True
else:
print lyr.name
lyr.visible = True
arcpy.RefreshActiveView()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment