AnsweredAssumed Answered

How can I use Arcpy to set label expression parser to Python?

Question asked by on Jan 28, 2018
Latest reply on Jan 28, 2018 by xander_bakker

I looked and looked but I can't find anything that lets the user to change the parser default to python for label expressions. The default is vb so when I run my arcpy script it list my python expression in the vb which doesn't work because it's in a different language. Can someone help me?


import os
import arcpy # if outside ArcMap

# inside ArcMap, use "CURRENT" for document name
mxd = arcpy.mapping.MapDocument(r"C:\Users\aa2zz6\Desktop\test\Untitled.mxd")
df = arcpy.mapping.ListDataFrames(mxd, '')[0]

for lyr in arcpy.mapping.ListLayers(mxd, "P_Meters"):
    if lyr.supports("LABELCLASSES"):
        print + " supports label classes"
        for lblClass in lyr.labelClasses:
            print lblClass.className
            lblClass.expression = lblClass.expression = '"{}" + [HOUSENUMBER] +  "{}"'.format("<CLR red = '255' green = '255' blue = '255'><FNT size = '10'>","</FNT></CLR>")
            if lblClass.showClassLabels:
                    print "    Class Name:  " + lblClass.className
                    print "    Expression:  " + lblClass.expression
    lyr.showLabels = True
del mxd