Select to view content in your preferred language

How to change the text color of an Annotation class via arcpy?

1317
5
Jump to solution
10-25-2023 02:26 AM
lbd_bayern
Occasional Contributor

I am struggling to change the text color of an Annotation class via arcpy.

For example, I have this in my ArcGIS Pro project:

lbd_bayern_0-1698225007437.png

A simple point which is annotated with the text "272.22". 

The properties of this instance "272.22" of the Annotation class look as follows (some attribute values are German; "Platziert" means "placed", "Nein" means "no", "Unten" means "Bottom", "Links" means "left", so nothing wild):

lbd_bayern_1-1698225159947.png

If I look at the properties of the layer of the Annotation class in the content tree, the following properties are displayed (again some German attributes and attribute values, but I think the concrete values are not relevant for the problem and pretty self-explanatory as well):

lbd_bayern_2-1698225451962.png

How can I change the color of all the texts of this Annotation class via arcpy?

In my arcpy script, I already have a reference to the corresponding layer object (acquired via the listLayers() method of the active map). The Annotation's layer does not have a symbology, so I can't change the color via symbology.renderer.symbol.color. Is there a way for Annotations? I am executing my script in the ArcGIS Pro python window.

 

 

0 Kudos
1 Solution

Accepted Solutions
CarstenB_orsted
Occasional Contributor

This code snippet makes all my annotation text blue 🙂

p = arcpy.mp.ArcGISProject("CURRENT")
m = p.listMaps()[0]
l = m.listLayers()[0]
cim_l = l.getDefinition('V3')
cim_l.symbolSubstitutionType = 'Color'
cim_l.massColorSubstitute.values = [0, 0, 255, 100]
l.setDefinition(cim_l)

I hope this can get you started! CIM is fun!

Regards

Carsten

View solution in original post

5 Replies
CarstenB_orsted
Occasional Contributor

 

I'm not sure you can do this with the functionality exposed in arcpy.

I think I would try CIM. It's a bit finicky to use, but you have access to all the settings that you have in the dialogs. The challenge is to find which setting to change in the huge JSONS.

More info here: Python CIM access—ArcGIS Pro | Documentation

I think I have seen a demo where they changed label colors using CIM. Maybe plenary at Developer Summit 2019?

Regards

Carsten

0 Kudos
CarstenB_orsted
Occasional Contributor

 

It was this one I was thinking about: Map Automation - Esri Videos: GIS, Events, ArcGIS Products & Industries

Not exactly labels, but think you can do something similar.

0 Kudos
CarstenB_orsted
Occasional Contributor

This code snippet makes all my annotation text blue 🙂

p = arcpy.mp.ArcGISProject("CURRENT")
m = p.listMaps()[0]
l = m.listLayers()[0]
cim_l = l.getDefinition('V3')
cim_l.symbolSubstitutionType = 'Color'
cim_l.massColorSubstitute.values = [0, 0, 255, 100]
l.setDefinition(cim_l)

I hope this can get you started! CIM is fun!

Regards

Carsten

lbd_bayern
Occasional Contributor

Hi Carsten,

nice, thank you so much! 😀 This is already what I needed. Cheers!

(PS: Sorry for my late response, had some stress in some other projects and also was sick for a few days.)

0 Kudos
CarstenB_orsted
Occasional Contributor

No worries. I am happy that you could use it!

0 Kudos