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
Solved! Go to Solution.
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).
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.
Are trying to change colors in a text element? What are you trying to do?
I want to create a label that I can change font color and background color of the text
ex: in below
ABC DE
Here's what you can do with labels
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...
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
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.
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).
Thank you.