Arcpy CIM Symbology Edits

I have a certain way that I like to symbolize polygons in personal projects. I like a thick, bold outline, semi-tranparent fill, and dark label, all along the same hue. I’ve symbolized enough data this way that I decided to write a script to do it instead of the tedious, manual process. Plus it gave me a chance to learn about ESRI’s Cartographic Information Model.

The result was a script that does most of what I wanted. The CIM allows you to write code using fine-grained aspects of ArcGIS Pro projects and resources. It did allow me to create symbology classes:

CLASS_FIELD = r'community'
symbology = layer.symbology
if hasattr(symbology, 'renderer'):
    symbology.updateRenderer('UniqueValueRenderer')
    symbology.renderer.fields = [CLASS_FIELD]
    for group in symbology.renderer.groups:
        for item in group.items:
            # Set symbol properties
            item.symbol.color = {'RGB': [207, 174, 224, 65]}
            item.symbol.outlineColor = {'RGB': [173, 159, 218, 0]}
            item.symbol.outlineWidth = 3
layer.symbology = symbology

Unfortunately, I ran into limitations that prevented me from doing everything I wanted. You can create label classes, but not update text size, color, etc:

CLASS_FIELD = r'community'
if layer.supports("SHOWLABELS"):
    layer.showLabels = True
    for label_list_item in LABEL_LIST:
        label_class = layer.createLabelClass(label,
            '$feature.' + CLASS_FIELD,
            CLASS_FIELD + ' = \'' + label + '\'', 'Arcade')
        label_class.visible = True

All in all it was a good learning experience, and a script I’ll use in the future. Check out the full script here:
https://github.com/bjs339/cim-layer/tree/main

1 thought on “Arcpy CIM Symbology Edits”

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top