I was using a script to rewrite the graded color labels with Arcpy, but it stopped working (maybe after I updated to 3.4.3).
I simplified the code and tested it, and the labels were set for just a moment, but then they went back to normal.
Is there something wrong with this code?
import arcpy
lyr="test"
tani="ha"
aprx=arcpy.mp.ArcGISProject("CURRENT")
view=aprx.activeView
mapname=view.map.name
maps=aprx.listMaps(mapname)[0]
l=maps.listLayers(lyr)[0]
label_count_last=l.symbology.renderer.breakCount
if hasattr(l.symbology, 'renderer'):
if l.symbology.renderer.type == 'GraduatedColorsRenderer':
sym = l.symbology
sym.renderer.lowerBound = -10000000 #3.4 lowerBound set on Renderer
for i in range(0,label_count_last):
brk=sym.renderer.classBreaks[i].upperBound
sym.renderer.classBreaks[i].label=str(brk)+tani
sym.renderer.classBreaks[-1].upperBound = 10000000 #upperBound set on upper ClassBreak
l.symbology = sym
When executed:
Solved! Go to Solution.
@-_- This is indeed a regression we discovered and fixed during 3.5 and will patch 3.4 with the next available patch. What happened was new behavior was added into the the software called "alwaysUpdateClassLabels". When you simply use the arcpy.mp API to update a class label, it got overwritten due to this new behavior.
aprx = arcpy.mp.ArcGISProject('CURRENT')
active_map = aprx.activeMap
lyr = active_map.listLayers()[0]
sym = lyr.symbology
sym.renderer.classBreaks[0].label = "Testing 123" #RESETS TO ORIG
lyr.symbology = sym
But as you discovered, if the labels are modified via the CIM, it bypasses internal behavior and works.
aprx = arcpy.mp.ArcGISProject('CURRENT')
active_map = aprx.activeMap
lyr = active_map.listLayers()[0]
lyr_cim = lyr.getDefinition('V3')
lyr_cim.renderer.breaks[0].label = "Testing 123" #This works
lyr.setDefinition(lyr_cim)
This applies to all renderers and colorizers with class breaks. Our apologies for the breaking change.
Jeff - arcpy.mp team
I see.
The latest version of the Japanese version I use is 3.4.3, so I didn't realize that there was a 3.5 version. I'm sorry.
I feel relieved now that I know the cause. Thank you.
@-_- Pro 3.5 is soon to be released but we will also patch Pro 3.4. The next patch will be Pro 3.4.4.
Jeff - arcpy.mp team