Hi all,
I wrote a Python script that reads some maps that already have "GraduatedColorsRenderer" with 8 breaks for symbology.
The script is supposed to use CIM definitions to change Legends Label formatting to Percentage with 1 decimal point.
The script runs without any errors but when you check the layer, the changes are not applied visually. Although when you check the "Advanced symbology" pane, it shows that the changes are there. (Also after running the script, if you call components in "l_cim.renderer.numberFormat" it shows the changes are made.
If you manually "refresh values" in "primary symbology" pane or change the decimal point or check thousand separator checkbox in "Advanced symbology" pane, suddenly all the changes from before applies to the labels. (See the Screenshots and Script below)
Question 1) Is there any refresh method I should use or that's just a bug?
Question 2) How to change the option to Number represented as fractions (using python)
Here is an example of the issue:
Before Running the Script:
(Actual legend on the left and the formatting setting on the right)
After Running the Script:
Category and decimal places changed on the right,
but the actual labels are the same as before
After Changing Decimal places to 2:
Here is the python Script:
import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
#list of current map names
map_list = ['map_cityA', 'map_cityB', 'map_cityC' ]
# set symbology for each map
for map_name in map_list:
mp = aprx.listMaps(map_name)[0]
for lyr in mp.listLayers():
if lyr.isFeatureLayer:
l_cim = lyr.getDefinition('V3')
# create an empty empty numeric object for percentage
num_obj = arcpy.cim.CreateCIMObjectFromClassName('CIMPercentageFormat', 'V3')
num_obj.alignmentOption = 'esriAlignLeft'
num_obj.alignmentWidth = 12
num_obj.roundingOption = 'esriRoundNumberOfDecimals'
num_obj.roundingValue = 1 # decimal places to show
num_obj.zeroPad = False
# num_obj.useSeparator = False
num_obj.showPlusSign=False
# assign the new numeric object to the renderer's number format
l_cim.renderer.numberFormat = num_obj
lyr.setDefinition(l_cim) #set the CIM
# tried to force it to refresh (did not work)
l_cim = lyr.getDefinition('V3')
lyr.setDefinition(l_cim)
#save project after
aprx.save()
Thank you all!
My platform: Windows 11 (22H2) and ArcGISPro 3.1.0