Create script for advanced feature labelling

1218
3
05-24-2021 08:02 PM
DavidField
New Contributor III

Hello,

I am trying to work out if it is possible to create a script for ArcGIS Pro that allows me to turn on labels for a feature, and then lets me control:

-colour

-font size

-halo on / off

-halo colour

-halo width

Ideally the script would have user-defined inputs for all of the above.

It seems that this may be possible in ArcMap, but I can't seem to find any discussion for ArcGIS Pro. Can anyone point me to documentation, code samples or a tutorials that might get me started?

Cheers

0 Kudos
3 Replies
DavidField
New Contributor III

I was thinking something along the lines of the following code might work, but it only seems to affect the halo width, all other properties are unchanged:

featurename = arcpy.GetParameterAsText(0)
labelcolumn = str(arcpy.GetParameterAsText(1))

aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.activeMap

for lyr in m.listLayers(featurename):
lblClass = lyr.listLabelClasses()[0]
lblClass.expression = "[" + labelcolumn + "]"

# Get the layer's CIM definition
l_cim = lyr.getDefinition('V2')

# Get first label class
lc = l_cim.labelClasses[0]

# Set label class symbol properties
lc.textSymbol.symbol.color = 'white'
lc.textSymbol.symbol.font = 8
lc.textSymbol.symbol.haloColor = 'black'
lc.textSymbol.symbol.haloSize = 1

# Set layer's CIM definition
lyr.setDefinition(l_cim)

# Show labels
lyr.showLabels = True

0 Kudos
mody_buchbinder
Occasional Contributor III

I just add tags. See this: https://pro.arcgis.com/en/pro-app/latest/help/mapping/text/text-formatting-tags.htm 

Then you change the expression only.

It works for me

0 Kudos
DavidField
New Contributor III

Thanks for your reply!

I had a look at tags, they look much more user-friendly, however I don't think they will allow me to adjust halo settings?

0 Kudos