1
$\begingroup$

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?

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

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

$\endgroup$
  • $\begingroup$ Thank you very much!! It worked well. $\endgroup$ – ぬらとん Aug 26 '19 at 9:22
  • $\begingroup$ 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? $\endgroup$ – lemon Aug 26 '19 at 9:31
  • 1
    $\begingroup$ @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\ $\endgroup$ – Robin Betts Aug 26 '19 at 11:20
  • 1
    $\begingroup$ @RobinBetts, thanks... had just mingled 'down' and 'bottom'... my bad! $\endgroup$ – lemon Aug 26 '19 at 11:30
1
$\begingroup$

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

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.