The arcpy.mapping API only provides access to a limited number of
layer properties that can be directly modified but all properties
found in the Layer Properties dialog box can be modified using the
UpdateLayer function. The information is extracted from a source layer
and applied to the layer in a map document that needs to be updated.
The source_layer can either be a layer (.lyr) file or a layer within a
map document. UpdateLayer is a robust function because it can be used
in several different ways to produce different results.
You need to create the symbology/labels how you want, and save it to a layer file. Then load that layer file using arcpy.mapping.UpdateLayer().
If multiple people need to run the python add-in, then you need to make the layer file accessible to everyone, such as a public network drive.
I ended up making a custom Update Layer Properties toolbox. It allows you to select a layer in the ArcMap TOC, and then select an input layer file. It then updates the layer with all the properties within the layer file, and re-sources back to the original feature class. It will work with data that's in gdb, mdb, shp, or sde.
View the Source Code
Please let me know if you have any questions.
Proposed expression for the Geometry Generator:
-- algorithm inspired by https://github.com/haubourg/EasyCustomLabeling/blob/master/EasyCustomLabeling/EasyCustomLabeling.py
line 260 and next
case
when "auxiliary_storage_labeling_positionx" < $x and "auxiliary_storage_labeling_positiony" > $y and abs("auxiliary_storage_labeling_positiony"-$y) < abs("auxiliary_storage_labeling_positionx"-$x)
then make_line($geometry, make_point($x-abs("auxiliary_storage_labeling_positiony"-$y),"auxiliary_storage_labeling_positiony"),make_point("auxiliary_storage_labeling_positionx", "auxiliary_storage_labeling_positiony"))
when "auxiliary_storage_labeling_positionx" < $x and "auxiliary_storage_labeling_positiony" > $y and abs("auxiliary_storage_labeling_positiony"-$y) >= abs("auxiliary_storage_labeling_positionx"-$x)
then make_line($geometry, make_point($x,abs("auxiliary_storage_labeling_positionx"-$x)+$y),make_point("auxiliary_storage_labeling_positionx", "auxiliary_storage_labeling_positiony"))
when "auxiliary_storage_labeling_positionx" < $x and "auxiliary_storage_labeling_positiony" < $y and abs("auxiliary_storage_labeling_positiony"-$y) < abs("auxiliary_storage_labeling_positionx"-$x)
then make_line($geometry, make_point($x-abs("auxiliary_storage_labeling_positiony"-$y),"auxiliary_storage_labeling_positiony"),make_point("auxiliary_storage_labeling_positionx", "auxiliary_storage_labeling_positiony"))
when "auxiliary_storage_labeling_positionx" < $x and "auxiliary_storage_labeling_positiony" < $y and abs("auxiliary_storage_labeling_positiony"-$y) >= abs("auxiliary_storage_labeling_positionx"-$x)
then make_line($geometry, make_point($x,$y-abs("auxiliary_storage_labeling_positionx"-$x)),make_point("auxiliary_storage_labeling_positionx", "auxiliary_storage_labeling_positiony"))
when "auxiliary_storage_labeling_positionx" >= $x and "auxiliary_storage_labeling_positiony" > $y and abs("auxiliary_storage_labeling_positiony"-$y) > abs("auxiliary_storage_labeling_positionx"-$x) --quadrant ur alternatif
then make_line($geometry, make_point($x,"auxiliary_storage_labeling_positiony"-abs("auxiliary_storage_labeling_positionx"-$x)),make_point("auxiliary_storage_labeling_positionx", "auxiliary_storage_labeling_positiony"))
when "auxiliary_storage_labeling_positionx" >= $x and "auxiliary_storage_labeling_positiony" > $y and abs("auxiliary_storage_labeling_positiony"-$y) < abs("auxiliary_storage_labeling_positionx"-$x)
then make_line($geometry, make_point($x+abs("auxiliary_storage_labeling_positiony"-$y),"auxiliary_storage_labeling_positiony"),make_point("auxiliary_storage_labeling_positionx", "auxiliary_storage_labeling_positiony"))
when "auxiliary_storage_labeling_positionx" >= $x and "auxiliary_storage_labeling_positiony" <= $y and abs("auxiliary_storage_labeling_positiony"-$y) > abs("auxiliary_storage_labeling_positionx"-$x)
then make_line($geometry, make_point($x,$y-abs("auxiliary_storage_labeling_positionx"-$x)),make_point("auxiliary_storage_labeling_positionx", "auxiliary_storage_labeling_positiony"))
when "auxiliary_storage_labeling_positionx" >= $x and "auxiliary_storage_labeling_positiony" <= $y and abs("auxiliary_storage_labeling_positiony"-$y) < abs("auxiliary_storage_labeling_positionx"-$x)
then make_line($geometry, make_point($x+abs("auxiliary_storage_labeling_positiony"-$y),"auxiliary_storage_labeling_positiony"),make_point("auxiliary_storage_labeling_positionx", "auxiliary_storage_labeling_positiony"))
end
and for label position (horizontal alignment) :
CASE
WHEN "auxiliary_storage_labeling_positionx" < $x THEN 'right'
ELSE 'left'
END
Best Answer
You can set a label color using expressions, but not in the label value field. You need to use the datadefined override for the color selector.
Example:
The above expression sets the color to red if true and black if false.
To help you build your expression you can also use the "Assistant..." when clicking on the datadefined override button to the right of the color selector.