Select to view content in your preferred language

UniqueValueRenderer re-arrange classes

249
0
11-28-2023 12:04 PM
TylerT
by
Occasional Contributor III

Hello,

I am looking to rearrange classes in a SINGLE layer using arcpy mp.  Here's a visual sample only:

TylerT_0-1701201278480.png

The documentation suggests LegendItems items is not settable (see image below) in basic arcpy.mp, although I did try and got an error suggesting the same.  

TylerT_0-1701203234568.png

TylerT_0-1701203168633.png

So, I drilled into the CIM renderer groups , but can't quite get it working.  The resulting map is void of symbology.  Here's what I have so far.

 

# move Duplex legend/class to end
l_cim = lyr1.getDefinition('V2')
for grp in l_cim.renderer.groups:
    for cls in grp.classes:
        if cls.label == 'Duplex':
            grp.classes = [x for x in grp.classes if x != cls] + [cls]
lyr1.setDefinition(l_cim)

 

 Viewing the list grp.classes before and after shows the Duplex object moved to the end of the list, so I suppose there is more going on under the hood...or I'm missing something.  


Bottom line is I'm looking to mimic/automate this GUI behavior from the symbology pane (or by right clicking a class > reorder (top, up, down, bottom).  Any tips would be appreciated.

TylerT_2-1701203735909.png


Tyler

0 Kudos
0 Replies