Edited
When creating feature layers using ArcPy:
There doesn’t seem to be a way to Vary symbology by rotation using ArcPy.
Could that functionality be added?
Related: ArcPy script to convert layer to individual feature layers for each symbology class
https://community.esri.com/t5/arcgis-pro-sdk-questions/customize-pro-ui-checkboxes-in-toc-to-toggle/...
Symbol—ArcGIS Pro | Documentation
angle
(Read and Write)
Gets and sets the rotation value of a point symbol.
Double
The question is a bit unclear.
Yes, there is symbol.angle, but that sets the angle value of each symbol.
What @Bud means is that there is no way in arcpy to Vary symbology by rotation—ArcGIS Pro | Documentation
This is something we can consider but it will be a long time before we can provide this level of detail via the curated API. In the meantime, the CIM may be an option. Before reviewing the code below it may be worth reviewing the Python CIM Access help topic:
https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/python-cim-access.htm
I started with:
As suggested in the topic above, I created a before and after layer, saved them to LYRX files and compared the JSON differences.
Here is the code based on what I see above. The before layer didn't have visual variable applied so I had to create the appropriate CIM objects, set the values to match above and then apply the newly created visual variable to the empty visual variable list associated with the layer.
p = arcpy.mp.ArcGISProject('current')
m = p.listMaps('Map')[0]
l = m.listLayers('*BEFORE')[0]
maxLabel = 360 #this could be automated
#Create a rotation visual variable via the CIM
l_cim = l.getDefinition('V3')
visVar = arcpy.cim.CreateCIMObjectFromClassName('CIMRotationVisualVariable', 'V3')
#Xinfo
visVar.visualVariableInfoX.randomMax = maxLabel
visVar.visualVariableInfoX.visualVariableInfoType = "None"
#Yinfo
visVar.visualVariableInfoY.randomMax = maxLabel
visVar.visualVariableInfoY.visualVariableInfoType = "None"
#Zinfo
visVar.visualVariableInfoZ.randomMax = maxLabel
visVar.visualVariableInfoZ.visualVariableInfoType = "Expression"
#Create expression for Xinfo
expInf = arcpy.cim.CreateCIMObjectFromClassName('CIMExpressionInfo', 'V3')
expInf.title = "Custom"
expInf.expression = "$feature.Rotation" #field called rotation
expInf.returnType = "Default"
visVar.visualVariableInfoZ.valueExpressionInfo = expInf
visVar.rotationTypeZ = "Arithmetic"
l_cim.renderer.visualVariables.append(visVar) #Apply visual variable
l.setDefinition(l_cim) #set back to layer
And the final result:
I hope this helps,
Jeff - Layout and arcpy.mp teams
Thanks Jeff, that helps alot.
I have done some work with the CIM (especially configuring popups), but I haven't looked too far into it regarding symbology.
@JeffBarrette Hi, I looked at your code and tried to implement it, but it didn't change my lyrx file as far as I can see.
Is there a difference between 'V3' and 'V2' or shouldn't that make any difference?
Thanks in advance
@AndreasB V2 is intended for Pro 2x but will continue to work in 3x. If they both don't work they way you are expecting then nothing was changed in the 2x CIM vs 3x. I would need to see more of your code to understand what is not working.
Jeff - Layout and arcpy.mp teams
@JeffBarrette Thanks to your solution, Through cim, lyrx applied rotation and size was extracted from arcgis pro arcpy. However, I would also like to apply this to arcmap (arcgis desktop), but, on the arcmap arcpy, the getDefinition function does not seem to be available in Layer objects. I wonder if there is a possible way in arcmap arcpy.
@fireapple Python CIM access is not available to arcpy.mapping (for ArcMap). ArcGIS Pro projects and document settings use the CIM specification for persistance where MXDs do not.
Jeff - arcpy.mp and Layout teams
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.