1
$\begingroup$

Is there any way to toggle blender's Boolean command state while pushing keyboard shortcut? I always enable weight paint tool's Restrict mode but sometimes I need to disable it. I would like to disable weight paint tool's Restrict mode while I keep pushing keyboard shortcut and when I release the key Restrict mode needs to be enabled again. I would like to do something like sculpt tool's temporal smooth brush which is activated when I keep pushing shift key.(default setting of sculpt tool shift key works as sculpt.brush_stroke with Stroke Mode:Smooth)

I assigned 2 custom python script to A key.

this one works when A key is pushed

bpy.context.scene.tool_settings.weight_paint.use_group_restrict = False

And this one works when A key is released

bpy.context.scene.tool_settings.weight_paint.use_group_restrict = True

but it doesn't work always. When I push A key it surely disables Restrict mode but sometimes Blender fails to get key release state and 2nd python script isn't executed. I guess it's because I do weight paint while I keep pushing A key, and this brush stroke thing disrupts Key release event?

If you know much smarter way please tell me.

$\endgroup$

1 Answer 1

1
$\begingroup$

You may consider assign both keymap to a operator

Since you cannot execute another operator when the built-in operator modal is running, it will fail in some cases,
Success disable and enable: Hold A then hold Left mouse to paint, release left mouse and release A.
Success disable only: Hold A then hold Left mouse to paint, release A then release left mouse.

enter image description here

import bpy

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

    def invoke(self, context, event):
        bpy.context.scene.tool_settings.weight_paint.use_group_restrict = event.value != "PRESS"
        return {'FINISHED'}

def register():
    bpy.utils.register_class(SimpleOperator)

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

if __name__ == "__main__":
    register()
$\endgroup$
3
  • $\begingroup$ it works thank you but like you said releasing A key before releasing Left Click disrupts A key release event. seems I need to use other application like AHK to control Left Click release state. $\endgroup$
    – Yokomizo
    Commented May 2 at 17:58
  • $\begingroup$ Yes, there doesn't seem to be an simple way to do this., unless you can rewrite the paint operator: paint.weight_paint $\endgroup$
    – X Y
    Commented May 2 at 18:04
  • $\begingroup$ never mind AHK script won't work. Simply Weight Paint Brush event keeps disrupting A key release event. Thank you for anyway. $\endgroup$
    – Yokomizo
    Commented May 2 at 18:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .