Create new label class with python?

4229
4
10-16-2014 12:56 PM
DerrickKo_Heinrichs
New Contributor II

Unsuccessfully trying to create a new label class using python. Forums have been helpful for figuring out python for the label class SQL query & expression, but now I want to add another class with a new query & expression.

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

what example are you working with?

0 Kudos
DerrickKo_Heinrichs
New Contributor II

Within a forest inventory I want to label certain types of forest polygons differently, as well as wetlands and other non-forest features. How do I post my python script!? (this is my first time posting a question here!)

0 Kudos
DanPatterson_Retired
MVP Emeritus

copy and paste it here then use the Advanced Editor in the top right of the post frame then look for the >> then select syntax highlighting and select python

0 Kudos
DerrickKo_Heinrichs
New Contributor II

Here's what I've got so far. I'm relatively new to python & have learned by trial & error & reading through these forums. What the below seems to do is rename the 'Default' label class. How do I add a new label class?

# Create Label Class for Single Layer Forested polys

for lyr in arcpy.mapping.ListLayers (mxd): 

    if lyr.name == MAPSHEET:

        if lyr.supports("LABELCLASSES"):

            for lblclass in lyr.labelClasses:

                lblclass.showClassLabels = True

        lblclass.className = "FLsingle"

        lblclass.SQLQuery = "\"CANLAY\" = 'S' AND \"US2CANLAY\" IS NULL"

        lblclass.expression = "\"{0}\" + [CANLAY] +  \" - CC:\"  +  [CC] + \"{1}\"".format("<CLR red='0' blue='255' green='0'><FNT size = '11'>","</FNT></CLR>") # expression is currently incomplete

        lyr.showLabels = True

        arcpy.RefreshActiveView()

0 Kudos