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´m trying to label features of a dataset using ArcPy and the lblclass function. While commands like "VBNewline" and "Round" work pretty well, I´m not able to change colors or font style. An expression that works in ArcMap doesn´t work in the script. Could anyone help me out please? I´m using ArcGIS 10.0

Code that works:

 #Adding Labels
    layer = arcpy.mapping.ListLayers(mxd, "")[0] 
    if layer.supports("LABELCLASSES"):
        for lblclass in layer.labelClasses:
            lblclass.className = "Flaeche"
            lblclass.expression = "[FID] & VBNewLine & Round([AREA_mm2],2)"
        lblclass.showClassLabels = True
    layer.showLabels = True
    arcpy.RefreshActiveView() 

Code that works in ArcMap but not in ArcPy

#Adding Labels
layer = arcpy.mapping.ListLayers(mxd, "")[0] 
if layer.supports("LABELCLASSES"):
    for lblclass in layer.labelClasses:
        lblclass.className = "Flaeche"
        lblclass.expression = ""<CLR red='255' green='0' blue='0'>" & [FID] & VBNewLine & Round([AREA_mm2],2) & "</CLR>""
    lblclass.showClassLabels = True
layer.showLabels = True
arcpy.RefreshActiveView()
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

This code doesn't work because Python interpreter doesn't understand two double quotes in a row.
Instead you can try this:

lblclass.expression = '"%s" & [FID] & VBNewLine & Round([AREA_mm2],2) & "%s"' % ("<CLR red='255' green='0' blue='0'>", "</CLR>")
share|improve this answer
    
Thanks, that works perfectly !! –  Martin Oct 12 '12 at 13:00
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.