To switch the active tool from the T-panel in the 3D viewport window, we need to call the appropriate operator and pass the “idname” of the required tool in its “name” parameter.
For example, to enable the “Select Circle” selection toll, we need to call:
1 2 3 |
import bpy bpy.ops.wm.tool_set_by_id(name='builtin.select_circle') |
If we need to call an operator not from the 3D viewport area, but for example from a script in the Text Editor, we need to call the operator with the overridden area context.
1 2 3 4 5 6 7 8 9 10 11 12 |
import bpy area = [area for area in bpy.context.screen.areas if area.type == "VIEW_3D"][0] override_context = bpy.context.copy() override_context['window'] = bpy.context.window override_context['screen'] = bpy.context.screen override_context['area'] = area override_context['region'] = area.regions[-1] override_context['scene'] = bpy.context.scene override_context['space_data'] = area.spaces.active bpy.ops.wm.tool_set_by_id(override_context, name='builtin.select_circle') |