As part of larger process I'm trying to Enable Symbol Layer Drawing.
1. I tried using the CIM through the Layer class, which didn't work (I may have set it up wrong) and I foolishly deleted my code out of annoyance.
2. I also tried using the renderer (without the CIM):
sym = lyr.symbology
sym.updateRenderer('UniqueValueRenderer')
sym.renderer.enableSymbolLayerDrawing = True
lyr.symbology = sym
3. Here's my full code currently:
import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps(map_name)[0]
lyr = m.listLayers(layer_name)[0]
cim_lyr = lyr.getDefinition("V3")
for lblClass in cim_lyr.labelClasses:
lblClass.expressionEngine = "VBScript"
lblClass.expression = '"<FNT name=\'Arial\' style=\'Bold\' size=\'8\'><CLR red=\'255\' green=\'255\' blue=\'255\'>" & [ParcelID] & vbNewLine & [OpCo] & " " & [TypeOfUse] & "</CLR></FNT>"'
if not lblClass.maplexLabelPlacementProperties:
lblClass.maplexLabelPlacementProperties = arcpy.cim.CreateCIMObjectFromClassName('CIMMaplexLabelPlacementProperties', 'V3')
lblClass.maplexLabelPlacementProperties.polygonFeatureType = "LandParcel"
lblClass.maplexLabelPlacementProperties.polygonPlacementMethod = "StraightInPolygon"
lblClass.maplexLabelPlacementProperties.preferHorizontalPlacement = True
lblClass.maplexLabelPlacementProperties.multiPartOption = "OneLabelPerPart"
lblClass.maplexLabelPlacementProperties.featureWeight = 0
lblClass.maplexLabelPlacementProperties.labelWeight = 0
lblClass.maplexLabelPlacementProperties.polygonBoundaryWeight = 0
lblClass.maplexLabelPlacementProperties.avoidOverlappingLabeledPolygonsAsIfHoles = True
lblClass.maplexLabelPlacementProperties.canRemoveOverlappingLabel = False
lblClass.maplexLabelPlacementProperties.canPlaceLabelOnTopOfFeature = True
lblClass.maplexLabelPlacementProperties.canOverrunFeature = True
lblClass.maplexLabelPlacementProperties.canPlaceLabelOutsidePolygon = False
lblClass.maplexLabelPlacementProperties.backgroundLabel = True
lblClass.visibility = True
lblClass.priority = 0
sym = lyr.symbology
sym.renderer.enableSymbolLayerDrawing = True
lyr.showLabels = True
m.enableMaplex = True
lyr.symbology = sym
lyr.setDefinition(cim_lyr)
print(f" Label settings updated for {layer_name}")
Any ideas or thoughts are appreciated!
- Daniel