0
$\begingroup$

Back again with another add-on in development. The add-on that I am currently working on is a Viewport Sidebar version of the Properties Editor, with various improvements that are just not possible with the Properties Editor, such as reordering the tabs, as well as the benefit of not needing to have the Properties Editor open and taking up valuable screen space.

However, I'm taking things one step further... and it's that one step further that I'm having trouble with.

What I am trying to do currently is get the Shape Key box from Mesh Object Data Properties working in Pose Mode in order to use shape keys for facial expressions or anything else that uses them without having to switch between Object and Pose Mode.

The most obvious one that I’ve tried is the following:

class VIEW_3D_PT_animation_properties_shape_keys (bpy.types.Panel):

    bl_space_type = ‘VIEW_3D”
    bl_region_type = ‘UI’
    bl_category = “Properties”
    bl_label = “Shape Keys”
    bl_parent_id = “view3d.animation_properties”
    bl_options = {“DEFAULT_CLOSED}
    bl_context = “pose_mode”

    def draw (self, context):
        layout = self.layout

    if context.object.mode == “POSE” and context.object.type == “ARMATURE”:

    row = layout.row (align = True)
            row.template_list ("MESH_UL_shape_keys", "", context.object.data.shape_keys, "key_blocks", context.object, "active_shape_key_index")

However, when I run the script with Alt P, then go into Pose Mode, obviously, the Shape Key Panel doesn’t work as intended.

I get this….

enter image description here

When what I'm really aiming for is this:

enter image description here

Thanks to user SpectralVectors on Blender Artists for making me aware of bl_context. I never would’ve known it was a thing otherwise.

SpectralVectors also gave me the following code block to try out:

data = bpy.data.shape_keys[0]

            box = layout.box()

            for block in data.key_blocks:
                    column = box.column()
                    column.prop (block, "value", text = block.name)

And although it does work for using the shape keys in Pose Mode, it’s not the shape key menu, which is what I’m really after, nor does it take the currently selected mesh object/bound armature into account, although just learning about bl_context is a good enough start.

Sadly, I don’t know of any existing add-ons that take the object data properties context of one mode, and use it for another mode, so I have no clue if it’s even possible to do, but I believe it is since Blender Python can access everything else in Blender, so it’s possible that this is completely new territory, and if so, that means if we can figure out a solution for this to get the Shape Key Menu working in Pose Mode, people can use the solution provided as a template for other context sensitive things in Blender, which would help the overall Blender community.

If someone can find a working solution for the Shape Key Menu, that person will be mentioned in the author field for my addon, along with receiving a non-expiring discount for all products on my Gumroad store, so, please, Blender community, I can’t do this alone anymore.

$\endgroup$

0

You must log in to answer this question.

Browse other questions tagged .