Last active
August 29, 2015 14:17
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# @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