1
$\begingroup$

Is it possible to select and setup a tool, by hotkey, or from python ?

For example :

Keymap.py

("wm.tool_set_by_id",
    {"type": 'BUTTON4MOUSE', "value": 'ANY'},
    {"properties":
        [("name", 'builtin.select_circle<<<< (wait_for_input="False", mode="SUB") >>>>'),
        ],
    },
)

(the example target is a Select Circle -Operator with Subtract -Mode)

$\endgroup$
12
  • $\begingroup$ Hello :). Like this? How to activate different tool gizmos with shortcuts? $\endgroup$ Commented Jan 8, 2021 at 9:45
  • 1
    $\begingroup$ @JachymMichal i fixed the title, it was made incorrect by other user . $\endgroup$
    – irvnriir
    Commented Jan 8, 2021 at 11:14
  • 1
    $\begingroup$ So, if I understand right, what you call "Tool" is a blender operator ? The answer is the same, Press F3 for the search operator, type in the name of the operator, right click, assign shortcut $\endgroup$
    – Gorgious
    Commented Jan 8, 2021 at 12:53
  • 1
    $\begingroup$ blender.stackexchange.com/q/196483/86891 ? $\endgroup$
    – Gorgious
    Commented Jan 8, 2021 at 13:00
  • 1
    $\begingroup$ Imagine all the time neither of us would have wasted had you included this in your question ! :) Short answer is, you can't since this operator, as you can see in the docs you linked, does not have a "mode" parameter. i.sstatic.net/IoPgy.png $\endgroup$
    – Gorgious
    Commented Jan 8, 2021 at 13:34

1 Answer 1

3
$\begingroup$

Similar to Enable/disable 3D cursor tool properties from python

You can set the active tool using bpy.ops.wm.tool_set_by_id(name="builtin.select_circle") and use ToolSelectPanelHelper class to get a reference to it. Code based on Operator Simple template:

import bpy
from bl_ui.space_toolsystem_common import ToolSelectPanelHelper

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

    def execute(self, context):
        # Set the cursor tool
        bpy.ops.wm.tool_set_by_id(name = "builtin.select_circle")
        # Get the tool
        tool = ToolSelectPanelHelper.tool_active_from_context(context)
        props = tool.operator_properties('view3d.select_circle')

        # Print all properties
        print (dir(props))
        # [...'mode', 'radius', 'rna_type', 'wait_for_input', 'x', 'y']
        
        # Set the properties
        props.mode = 'SUB'
        props.radius = 50
        
        return {'FINISHED'}


addon_keymaps = []

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

    # Add a shortcut
    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon
    if kc:
        km = wm.keyconfigs.addon.keymaps.new(name='3D View', space_type='VIEW_3D')
        kmi = km.keymap_items.new(
            SimpleOperator.bl_idname, type='C', value='PRESS', ctrl=True, shift=True)
        addon_keymaps.append((km, kmi))


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

    # Remove the shortcut
    for km, kmi in addon_keymaps:
        km.keymap_items.remove(kmi)
    addon_keymaps.clear()


if __name__ == "__main__":
    register()

Press CtrlShiftC to enable the Cirle Select along with your custom tool settings (mode and radius in this case).

$\endgroup$
2
  • $\begingroup$ Thank you . So it can't be achieved without python ? That feature should be (added) in Keymap . $\endgroup$
    – irvnriir
    Commented Jan 8, 2021 at 14:18
  • 1
    $\begingroup$ I don't think a feature like this should be added. I have a feeling that the percentage of people who might need a feature like this is astronomically small and there are plenty of features way more important waiting to be added - just my opinion... But that small percentage of people can always ask for help from the community and get exactly what they want like in this instance. This is a very nice script and a very nice answer! $\endgroup$ Commented Jan 8, 2021 at 15:11

You must log in to answer this question.

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