Multiple character meshes using same shapekey names, how identify key ID of active mesh?

Hi, I’m trying to control character expression shapekeys using X-Pose Picker. All of my characters have shapekeys with some identical names like “Smile”, “Sad”, “Anger” etc. I’ve created a tab in X-pose picker where I can quickly change the value of these keys without having to exit pose mode to access object data properties.

Currently, if there is only one character loaded into the scene, these scripted expression buttons have no problem changing the shapekey. Once another character is added, bpy.data.shape_keys[“Key”] adds a randomly assigned number to specify which Key. bpy.data.shape_keys[“Key.009”].

So the following scenario will happen:
Char1 = bpy.data.shape_keys[“Key.009”]
Char2= bpy.data.shape_keys[“Key.016”]
Char3 = bpy.data.shape_keys[“Key.004”]

How can I script to retrieve the current active mesh key?

Not familiar with this addon thingy, but the current active object is

bpy.context.view_layer.objects.active

you can also get the currently selected objects as a collection from

bpy.context.selected_objects

1 Like

Thanks jaxtraw. I’ve tried bpy.context.selected_objects but don’t see a way to find the key ID through this. What I’m trying to accomplish isn’t related to the x-pose picker plugin.

When I select a character and change a shapekey, there’s a number following the key.
image

image

One character just says “Key” while the other character says “Key.009”.

Since the shape keys control expression and all characters share the same expressions, I wan’t to script buttons that target the current character and change the value of that shapekey by some amount.

Well I may be missing something here, apologies if so, but don’t you want the shape keys collection from the Active Object rather than the whole scene’s shape keys? That would be

bpy.context.view_layer.objects.active.data.shape_keys

and

bpy.context.view_layer.objects.active.data.shape_keys.key_blocks

so, like

bpy.context.view_layer.objects.active.data.shape_keys.key_blocks[‘Smile_HD’]

is this any help?

1 Like

You responded just as I finally got to it with the following. Thanks so much for your time and help!

bpy.context.active_object.data.shape_keys.key_blocks[“Smile”].value=0

1 Like

And thanks for responding rather than just abandoning the thread :slight_smile:

1 Like