Create script for advanced feature labelling

05-24-2021 08:02 PM
New Contributor III


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:


-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?


0 Kudos
3 Replies
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 ="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

# Show labels
lyr.showLabels = True

0 Kudos
Occasional Contributor

I just add tags. See this: 

Then you change the expression only.

It works for me

0 Kudos
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