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 am unable to turn on the labels with the python script. I am not sure why! Please do not direct me to another post as i have read them all.

This is the most recent one i've tried, with obvious failure.

import arcpy
mxd = arcpy.mapping.MapDocument(r"Mypathhere") #Map document reference
layer = arcpy.mapping.ListLayers(mxd, "Layername")[0] #Indexing list for 1st layer
if layer.supports("LABELCLASSES"):
    for lblclass in layer.labelClasses:
        lblclass.showClassLabels = True
arcpy.RefreshActiveView()
mxd.save()
del mxd

Do i need to enable labeling in the label manager first? Can that be done with arcpy? Thanks for your help!

The script does not break, i don't get any errors, the points just don't get labeled.

share|improve this question
1  
What isn't working? Are you getting any errors? The more details you can provide on WHY or HOW your method is not working, the better answers you will get. –  RyanDalton Apr 30 '12 at 17:45
add comment

1 Answer

up vote 3 down vote accepted

I think your problem is that your code is enabling the checkbox under the Layer Properties that says "Label features in this class". The part you are missing is the code to enable to the checkbox for "Label features in this layer"

Try inserting this code:

layer.showLabels = True

After your if statement that activates the label classes, like the following:

import arcpy
mxd = arcpy.mapping.MapDocument(r"Mypathhere") #Map document reference
layer = arcpy.mapping.ListLayers(mxd, "Layername")[0] #Indexing list for 1st layer
if layer.supports("LABELCLASSES"):
    for lblclass in layer.labelClasses:
        lblclass.showClassLabels = True
layer.showLabels = True`
arcpy.RefreshActiveView()
mxd.save()
del mxd
share|improve this answer
    
Thanks your answer helped me out. –  CLJ Oct 17 '13 at 12:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.