Select to view content in your preferred language

Attempting to use showLabels script within a model...

481
2
Jump to solution
02-19-2013 09:25 AM
CraigMcDade
Deactivated User
I'm attempting to use a small script within my mxd (will later attach to a model) that will turn the labels on for a layer. My code is essentially straight from the Resource Center:

import arcpy mxd = arcpy.mapping.MapDocument(r"C:\path\to\my.mxd") for lyr in arcpy.mapping.ListLayers(mxd):   if lyr.description == "Layer Name":     lyr.showLabels = True del mxd arcpy.RefreshTOC() arcpy.RefreshActiveView()


I am running it with the mxd open from the python window. It looks like it is working because the map does refresh but the labels are not turning on.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JeffMoulds
Esri Contributor
If you want to see the result of scripts run in the Python Window in ArcMap reflected in the current map, reference the map document like this:
mxd = arcpy.mapping.MapDocument('current')


That should do what you want.

View solution in original post

0 Kudos
2 Replies
JeffMoulds
Esri Contributor
If you want to see the result of scripts run in the Python Window in ArcMap reflected in the current map, reference the map document like this:
mxd = arcpy.mapping.MapDocument('current')


That should do what you want.
0 Kudos
CraigMcDade
Deactivated User
If you want to see the result of scripts run in the Python Window in ArcMap reflected in the current map, reference the map document like this:
mxd = arcpy.mapping.MapDocument('current')


That should do what you want.


Thanks. Helped point me in the right direction.

I wound up with:

import arcpy
... mxd = arcpy.mapping.MapDocument("CURRENT") 
... layer = arcpy.mapping.ListLayers(mxd, "")[0] 
... if layer.supports("LABELCLASSES"):
...     for lblclass in layer.labelClasses:
...         lblclass.showClassLabels = True
... lblclass.expression = " [PARCELID]"
... layer.showLabels = True
... arcpy.RefreshActiveView()
0 Kudos