# How to sort Shape keys by “a to z” in blender 2.8?

In 2.79,we could sort them by "a to z".But in 2.8, the function has disappeared. Is there any addons or python scripts?

• you can find it by clicking an icon "⊕" at the bottom of the shape key tab. – ぬらとん Aug 26 '19 at 9:31
• oh yes you're right, it's actually an arrow, not a + – moonboots Aug 26 '19 at 9:40
• What else? Isn't that what you've searched for? @ぬらとん Otherwise please let me know. – brockmann Aug 28 '19 at 9:14

I'm no expert in this area, but something along the lines of this script, executed on the current active object, in Object Mode ?

import bpy

ob = bpy.context.object
skeys = ob.data.shape_keys.key_blocks

skey_names = sorted(skeys.keys(), key=lambda v: v.upper())

for name in skey_names:
idx = skeys.keys().index(name)
ob.active_shape_key_index = idx
bpy.ops.object.shape_key_move(type='BOTTOM')


which works, but any edits to improve style are welcome. I can't help thinking I've handled that list in a clunky way.

EDIT in response to @lemon's comment:

The reason I thought this was clunky was that I thought there was no guarantee of the order of keys in a Python dictionary. But 1... that's not true, and 2... I don't think it matters anyway.

• skey_names is just an independent alphabetically sorted list of strings; a snapshot of the dict-keys of the bpy_prop_collection of shape keys. We are assuming the contents of original property-dictionary will not be modified before the loop terminates, but assume nothing about order .

For each of those sorted names, in order ...

• ... the ordinary Python dictionary call of .index(str) returns its position in the current state of the original property-dictionary, wherever it is ...
• .. to be used to set the read/write .active_shape_key_index to make the shape key labeled by it active...
• ... so the context-sensitive bpy.ops.object.shape_key_move can send it to the bottom of the list, (preserving the order of the other items).

Sending each item to the bottom of the list in alphabetical order results in an alphabetically-sorted list

• Thank you very much!! It worked well. – ぬらとん Aug 26 '19 at 9:22
• Yes it is!! But am totally unable to understand how! I've print( name, idx ) and tried to do it manually but still don't get it. Could you explain, please? – lemon Aug 26 '19 at 9:31
• @lemon hope the edit helps .. I'm still feeling my way around Python, let alone the API, so I'm afraid my terminology might not be very clear.. what with shape-keys, key-keys, dictionary-keys.. 8\ – Robin Betts Aug 26 '19 at 11:20
• @RobinBetts, thanks... had just mingled 'down' and 'bottom'... my bad! – lemon Aug 26 '19 at 11:30

We still have sort by name option (AZ), it's hidden by default though. Just roll out the search options: