Labeling with Python

636
1
07-25-2013 10:10 AM
JoelJacobson
New Contributor
I'm trying to label features as part of a python script and I'm running into two problems:

A. How do I turn on the 'Advance' option for expressions? lblClass.expression.advanced = True?

B. How do I drop down a line? I'm trying to write the following expression into the 'Expression' box:

lblClass.expression = ("Function FindLabel ( [TargetName], [Residual] )" + '\n'  + \
                              "    If [Residual] > 0 then" '\n' \
                              "      FindLabel = [TargetName] & vbnewline & '<CLR red='0' green='0' blue='255'>' & [Residual] & '</CLR>'" '\n' \
                              "    else" '\n' \
                              "      FindLabel = [TargetName] & vbnewline & '<CLR red='255' green='0' blue='0'>' & [Residual] & '</CLR>'" '\n'\
                              "    end if" '\n' \
                              "End Function")


I'm completely new to Python so I have no idea if I'm close or if it's even possible. Thanks
Tags (2)
0 Kudos
1 Reply
RhettZufelt
MVP Frequent Contributor
What version are you running?  I have looked in 9.3, 10.0 and 10.1 and do not see an "Advanced" option for the label class expression so not sure what you are asking.

Here are the available label options with arcpy.mapping http://resources.arcgis.com/en/help/main/10.1/index.html#/LabelClass/00s30000002t000000/ which lists nothing about an advanced option.

Also, in the expression, using python parser, the following will add a new line between the values from my FAC_CODE and name fields.

[FAC_CODE]  + "\n " + [name] 


It appears as if you are trying to combine the lblClass.expression and lblClass.SQLquery into the expression box.
If you want it to label things differently based on a query/filter, you set up different labelclass's (with a different name for each)

So, you would create a labelclass named something like greaterthan with SQLquery=  If [Residual] > 0 and the expression that tells it how to label the features that match the query.
Then, you would create another labelclass named something like lessthan with SQLquery =  If [Residual] < 0 and the expression that tells it how to label the matching features.

So, basically, create a label class for each query and set the respective expressions to achieve what you are after.

R_

personally, I go into ArcMap and create my labelClasses, make sure the query/expressions are working (make sure you use the python parser), then I figure out the syntax to get them to work with python.
0 Kudos