← All ideas
  • Published 21 Dec 2022

Better rigify selection and movement of joints that need to stay together.

Rigifys face rig always breaks when it's adjusted and outputs errors that aren't usable. I've paid someone to make an addon to fix this but it doesn't work that well. I hope it works as a proof of concept tho.

What it is supposed to do is whenever the user selects part of a joint all of them are selected so they move together and don't break.

bl_info = {
    "name": "Joint_mover",
    "author": "Vikrant Pundir",
    "version": (0, 1),
    "blender" : (3, 00, 0),
    "category": "Rigging"
}

import bpy


def main(context):
    global c
    c = bpy.context

    global rig
    rig = c.view_layer.objects.active.name

    global bone
    bone = c.active_bone.name

    global boneList
    boneList = bpy.data.armatures[rig].bones

    global act_Head
    act_Head = bpy.data.armatures[rig].bones[bone].head_local

    global act_Tail
    act_Tail = bpy.data.armatures[rig].bones[bone].tail_local


def selector(locBoneVar):
    for i in boneList:
        if locBoneVar == boneList[i.name].head_local:
            bpy.data.armatures[rig].bones[i.name].select = False
            bpy.data.armatures[rig].bones[i.name].select_head = True
            print("in head")

        if locBoneVar == boneList[i.name].tail_local:
            bpy.data.armatures[rig].bones[i.name].select = False
            bpy.data.armatures[rig].bones[i.name].select_tail = True
            print("in tail")

    print ("-----")

def sel_init():


    if boneList[bone].select_head == True:
        selector(act_Head)

    if boneList[bone].select_tail == True:
        selector(act_Tail)


class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"

    def execute(self, context):
        print("hey")
        bpy.ops.object.mode_set(mode='OBJECT')

        main(context)
        sel_init()

        bpy.ops.object.mode_set(mode='EDIT')

        #invoke grab afe edit mode, else it will move the whole object
        bpy.ops.transform.translate('INVOKE_DEFAULT')

        return {'FINISHED'}

class addCubeSamplePreferences(bpy.types.AddonPreferences):
    bl_idname = __name__

    L_select: bpy.props.EnumProperty(
        items=[
            ('LMB', 'LMB select', '', '', 0),
            ('RMB', 'RMB select', '', '', 1)
        ],
        default='RMB'
    )

    def draw(self, context):
        layout = self.layout
        layout.label(text='Switch to Left mouse button select:')
        row = layout.row()
        row.prop(self, 'L_select', expand=True)


addon_keymaps = []
# Register and add to the "object" menu (required to also use F3 search "Simple Object Operator" for quick access).
def register():
    bpy.utils.register_class(SimpleOperator)
    bpy.utils.register_class(addCubeSamplePreferences)


    # Add the hotkey
    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon
    if kc:
        km = wm.keyconfigs.addon.keymaps.new(name='3D View', space_type='VIEW_3D')

        if bpy.context.preferences.addons['Joint_mover'].preferences.L_select == 'LMB':
            kmi = km.keymap_items.new(SimpleOperator.bl_idname, type='LEFTMOUSE', value='CLICK_DRAG')

        else:
            kmi = km.keymap_items.new(SimpleOperator.bl_idname, type='RIGHTMOUSE', value='CLICK_DRAG')
        addon_keymaps.append((km, kmi))


def unregister():
    bpy.utils.unregister_class(SimpleOperator)
    bpy.utils.register_class(addCubeSamplePreferences)

    for km, kmi in addon_keymaps:
        km.keymap_items.remove(kmi)
    addon_keymaps.clear()

if __name__ == "__main__":
    register()
100%

Development Status: Open

Upvote 1 Downvote 0
brah.rah
21 Dec 2022

1 Comment

Lauloque

Blender uses bones, not joints. They are composed of three parts: a head/root, a body and a tail/tip. You can think of the head and tail as two joints, one as start and one as end, and the body as the visual representation of the hierarchy of the joints' duo.
In pose mode you control the entirety of the bones, while in edit mode you can control the heads and tails individually.

It looks like your script is made to force bones tails and heads to move together. But that's completely unnecessary.
You need to be able to edit tails and heads individually in the first place. And when you want to move an entire bone at once, all you have to do is click the body of the bone to select the whole bone.

If you are having issues with Rigify specifically, I suggest you to first check if you are using it normally. And if you have an issue within its normal use, then send a bug report via the menu Help > Report a bug.