acrgis python add text background color

4950
9
Jump to solution
07-13-2015 10:11 AM
dz1
by
New Contributor

Is possible to add text background color using python on ArcGIS(ArcMap 10)? I wrote a function that able to change font color of the string but I want to add background color to it as well

def changeColor ([s1]):
 
return "<CLR red = '255'>" + [s1] + "</CLR>"

Following links show me how add background color manually http://resources.arcgis.com/en/help/main/10.2/index.html#/Creating_text_symbols/00s60000000z000000/

Is that a way that I can write a python script instead of doing manually?

thank

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

The only thing I can come up with is using label classes on a point featureclass:

As you can see, when the labels get close together (lower left) the formatting is changed..

Each feature has a label part1 and a label part2

In this case I only create a single color combination. However, you can add label classes with its corresponding color (for part 1 and 2 separately) and set the SQL Query according to the field values you want to distinguish. A feature is labeled twice: once for part 1 and once for part 2. Both use have the same placement property (prefer upper left) this causes the second part to be placed directly against the first part without the spacing which you would have if you define part 1 upper left and part 2 upper right.

This might take some time to tweak, but could work.

The option provided by Darren (copy the element with python) is an option, but you would have to handle overlapping labels manually and when you have a lot of features, will create a very dense layout (lots of elements).

View solution in original post

9 Replies
DarrenWiens2
MVP Honored Contributor

Aside from using ArcObjects with Python, I don't believe text background is directly customizable. At least, not through formatting tags or the TextElement object.

As a workaround, you could add a formatted text element to your mxd, then use it as a template for other TextElements.

WesMiller
Regular Contributor III

Are trying to change colors in a text element? What are you trying to do?

0 Kudos
dz1
by
New Contributor

I want to create a label that I can change font color and background color of the text

ex: in below

  ABC    DE  

0 Kudos
WesMiller
Regular Contributor III

Here's what you can do with labels

Aide ArcGIS (10.2, 10.2.1 et 10.2.2)

0 Kudos
XanderBakker
Esri Esteemed Contributor

As Darren Wiens  mentioned these properties are not exposed to arcpy and can only be changed using ArcObjects. It is not possible to achieve this with formatting tags. These are the only available ones:

http://resources.arcgis.com/en/help/main/10.2/index.html#//00s800000017000000

The only think I can think of, is that you is that you pre-create layers with different types of background colors (if the number of colors is low) and use these by changing the datasource and other aspects available through arcpy...

0 Kudos
dz1
by
New Contributor

I have few thousands data(only require five colors), I need to format the label according to it's string value. (It doesn't  need to be in label, It can be in any form) I just need to show something like this ABC EFGG on the map. Is there a way I can do this?

Is possible that I can create two label then I can combine these label into one?

for example:

label 1   +  label 2    = label 

ABC           EFG           ABC EFG

0 Kudos
DarrenWiens2
MVP Honored Contributor

Create one label for each color background, style the label as you want it, give it an ID, and save them in your mxd (off the map is fine). Then, you can access the TextElement by its ID, copy it, and position it, all through Python.

0 Kudos
XanderBakker
Esri Esteemed Contributor

The only thing I can come up with is using label classes on a point featureclass:

As you can see, when the labels get close together (lower left) the formatting is changed..

Each feature has a label part1 and a label part2

In this case I only create a single color combination. However, you can add label classes with its corresponding color (for part 1 and 2 separately) and set the SQL Query according to the field values you want to distinguish. A feature is labeled twice: once for part 1 and once for part 2. Both use have the same placement property (prefer upper left) this causes the second part to be placed directly against the first part without the spacing which you would have if you define part 1 upper left and part 2 upper right.

This might take some time to tweak, but could work.

The option provided by Darren (copy the element with python) is an option, but you would have to handle overlapping labels manually and when you have a lot of features, will create a very dense layout (lots of elements).

dz1
by
New Contributor

Thank you.

0 Kudos