Select to view content in your preferred language

python labeling

1360
8
Jump to solution
02-05-2013 04:26 PM
DavidO_Connor
New Contributor
Hi  - I'm just looking to start learning Python.  Starting with the absolute basics, I'd just like to make some labels with it.

On the help page here: http://resources.arcgis.com/en/help/main/10.1/index.html#//00s800000027000000  ,

It says "For example, you might use the bold formatting tag to make the first line bold in a stacked, multiline label".  That's exactly what I'd like to do, but I'm having trouble doing it.  So far I've been able to pull the five values from my attribute table and have a name for them, but I can't find out how to manipulate it any further.  Ideally, I'd like the first line to be bold and underlined, and for the all the lines to start at the same lateral position, which I think is called left justified.

Here's what I have so far:  [Location_I] + '\n' +"PCE: " + [PCE] + '\n' +"TCE: " + [TCE] + '\n' +"cDCE: " + [cDCE] + '\n' +"VC: " + [VC] + '\n' +"11DCE: " + [DCE_11DCE] + '\n' +"11DCA: " + [DCA_11DCA]

In the properties window of a pointfile feature class, I'm adding this into the label field after clicking on the expression button and selecting Python from the drop down list.  If you could point me to other examples or good reference pages, I would be grateful.

Thank you.

Dave
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MathewCoyle
Frequent Contributor
Yes the preview window is a little off when you start mixing different formatting tags. Stacking them is pretty simple, you just need to maintain first in last out order.

Good
"<BOL><UND>" + [Location_I] + "</UND></BOL>"


Bad
"<BOL><UND>" + [Location_I] + "</BOL></UND>"

View solution in original post

0 Kudos
8 Replies
MathewCoyle
Frequent Contributor
What issue are you having? Did you read the link at the top of the page you linked?

http://resources.arcgis.com/en/help/main/10.1/index.html#/Using_text_formatting_tags/00s80000000p000...

Edit: To bold you use "<BOL>" + [field] + "</BOL>"
Alignment I do not think is exposed through tags/code, you need to go into the symbol property and select left horizontal alignment.
0 Kudos
DavidO_Connor
New Contributor
Thank you very much Matthew.  I did read it closer! But it still seems something is wrong.

I entered:

"<BOL>" + [Location_I] + "</BOL>" + '\n' +"PCE: " + [PCE] + '\n' +"TCE: " + [TCE] + '\n' +"cDCE: " + [cDCE] + '\n' +"VC: " + [VC] + '\n' +"11DCE: " + [DCE_11DCE] + '\n' +"11DCA: " + [DCA_11DCA]


When I test the expression it is valid, but the sample image shows what looks like all the text is bold and mostly on top of itself, instead of being stacked. (picture attached).  When I remove the bold parts, and just enter the previous script, the label goes back to stacked.
0 Kudos
DavidO_Connor
New Contributor
Nevermind, it worked!

If it's not too hard, could you write how I would bold and underline for a  [field]?
0 Kudos
MathewCoyle
Frequent Contributor
Yes the preview window is a little off when you start mixing different formatting tags. Stacking them is pretty simple, you just need to maintain first in last out order.

Good
"<BOL><UND>" + [Location_I] + "</UND></BOL>"


Bad
"<BOL><UND>" + [Location_I] + "</BOL></UND>"
0 Kudos
JeffreyWittler
New Contributor

New to Python (or for that matter VBScript).  The instructions above seem straight forward but i am unable to get it to work.  The following is what I've tried to do

 

"<BOL><UND>"  +  [Section_Number]  +  "<UND><BOL>"  +   '\n '  +   [Planned_Plants] +  '\n '  +  [Acres_numeric] + ' ac'

 

That would hopefully produce the following result

3

1,110

1.3 ac

 

Below is the resulting label on my map:

<BOL><UND>3<UND><BOL>

1,110

1.3 ac

 

I'm obviously missing something but unable to identify what I'm doing wrong.  Any help would be much appreciated.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Try:

"<BOL><UND>"  +  [Section_Number]  +  "</UND></BOL>"  +   '\n '  +   [Planned_Plants] +  '\n '  +  [Acres_numeric] + ' ac'

You are closing the XML tags incorrectly.  Instead of <UND>, you need </UND>.

JeffreyWittler
New Contributor

Thank you!

Jeffrey Wittler | Environmental Resources Manager | Clark Public Utilities | p: 360.992.8577

0 Kudos
DavidO_Connor
New Contributor
Thank you.  It worked!
0 Kudos