4

I don't know how to set halo property in Python. I try it by CIM (code below) but I don't know, what line "lc.textSymbol.symbol.haloSymbol" should contain.

Can you advise me how to achieve halo effect using ArcPy?

aprx = arcpy.mp.ArcGISProject("current")
m = aprx.listMaps("Map15")[0]

show_labels = m.listLayers("okolni_listy_ztm5*")[0]
show_labels.showLabels = True

for lyr in m.listLayers("okolni_listy_ztm5*"):
if lyr.supports("SHOWLABELS"):
if lyr.showLabels:
for lblClass in lyr.listLabelClasses():
lblClass.expression = "$feature.OBJECTID"

label_show = m.listLayers('okolni_listy_ztm5*')[0]
l_cim = label_show.getDefinition('V2')
lc = l_cim.labelClasses[0]


lc.textSymbol.symbol.haloSize = 2
lc.textSymbol.symbol.haloSymbol = 

label_show.setDefinition(l_cim)

1 Answer 1

4

Below is the code required to alter the Halo of a Text Symbol. I have to say it's not particularly clear from the help file how to do it and it took me some time to work it out. The Python CIM access page was useful.

aprx = arcpy.mp.ArcGISProject("current")
myMap = aprx.listMaps("Map")[0]

myLayer = myMap.listLayers("Home")[0]
myLayer.showLabels = True

# Create a colour
fillRGBColour = arcpy.cim.CreateCIMObjectFromClassName('CIMRGBColor', 'V2')
fillRGBColour.values = [170,255,0, 100] #light green

# Create a fill
solFill = arcpy.cim.CreateCIMObjectFromClassName('CIMSolidFill', 'V2')
solFill.color = fillRGBColour
solFill.enable = True
solFill.colorlocked = False
solFill.overprint = False

# Create a polygon symbol and set its symbol layers
sym = arcpy.cim.CreateCIMObjectFromClassName('CIMPolygonSymbol', 'V2')
sym.symbolLayers = [solFill] # Note fill object is in a list, an append() would not work

# Get CIM definition
l_cim = myLayer.getDefinition('V2')
lc = l_cim.labelClasses[0] # Returns first CIMLabelClass object

# Update halo properties of text symbol
lc.textSymbol.symbol.haloSize = 2
lc.textSymbol.symbol.haloSymbol = sym

# Update CIM defintion
myLayer.setDefinition(l_cim)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.