How to Format Polygon Symbol via Python?

252
3
Jump to solution
01-10-2022 06:42 AM
dazu
by
New Contributor II

Is there a way to programmatically access and change the properties of a symbol (or part of it, e.g. pattern agnle) as shown in the window below?

I am aware of the symbol class and its properties.

ArcGISPro_2D8YbkG63d.png

0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

No.  You found CIM.  That is all for python access.


... sort of retired...

View solution in original post

0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

No.  You found CIM.  That is all for python access.


... sort of retired...
0 Kudos
dazu
by
New Contributor II

Wow... that was quick. Thank you, @DanPatterson, for pointing me to Esri's Cartographic Information Model.

The section Additional Resources and Sample Scripts links to the GitHub repository and a sample project with a script to create a dashed effect:

 

 

# Author:  Esri
# Date:    March 2020
# Version: ArcGISPro 2.5
# Purpose: This script creates or modifies the dash effects for a line symbol.
# Notes:   - The script is intended to work from a script tool provided with
#            a sample project using "CURRENT".  To see the changes happen be
#            sure to activate the appropriate map or layout.
#          - In addition to this sample script demonstating how the CIM
#            provides access to capabilities not in the managed Python API,
#            is also demonstrates a method for creating CIM objects that are
#            necessary to set desired properties.

p = arcpy.mp.ArcGISProject('current')
m = p.listMaps('Symbology')[0]
l = m.listLayers('States_SingleSymbol')[0]

l_cim = l.getDefinition('V2')         #Get the Layer's CIM definition

#Symbol Level 1 (Solid Stroke)
symLvl1 = l_cim.renderer.symbol.symbol.symbolLayers[0]

#If a dashed effect does not exist, create one
if len(symLvl1.effects) == 0:
  newDash = arcpy.cim.CreateCIMObjectFromClassName('CIMGeometricEffectDashes', 'V2')
  newDash.dashTemplate = [5, 5]
  symLvl1.effects = [newDash]
#If a dashed effects does exist, modify it
else:
  dash = symLvl1.effects[0]
  dash.dashTemplate = [10, 10]

l.setDefinition(l_cim)                #Set the Layer's CIM definition

 

 

This serves as a good starting point. Do you know of an easy way to expose the JSON structure of existing symbol styles? Or how to gain insight into the hierarchy?

0 Kudos
dazu
by
New Contributor II
help(arcpy.cim)
arcpy.cim.GetJSONForCIMObject(l_cim, "V2")
0 Kudos