3

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()

1 Answer 1

2

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>")
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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