Hey there!
I try to create tool selection shortcut, and it works as intended in view3d area, but can’t get any reaction in “uv editor mode”.
What am i doing wrong please
import bpy
# Function to switch the active selection tool based on mode
def switch_selection_tool():
# Check the area type
area_type = bpy.context.area.type
if area_type == 'VIEW_3D':
switch_selection_tool_3d_view()
elif area_type in {'IMAGE_EDITOR', 'UV_EDITOR'}:
switch_selection_tool_image_editor()
else:
print("Unsupported editor type")
# Function to switch the active selection tool in 3D Viewport mode
def switch_selection_tool_3d_view():
# Get the current mode
mode = bpy.context.mode
# Get the active tool ID
active_tool_id = bpy.context.workspace.tools.from_space_view3d_mode(mode, create=False).idname
# Switch selection tool based on the active tool ID
if active_tool_id == 'builtin.select_circle':
bpy.ops.wm.tool_set_by_id(name="builtin.select_box")
print("Switched to Box Selection Tool in 3D Viewport")
elif active_tool_id == 'builtin.select_box':
bpy.ops.wm.tool_set_by_id(name="builtin.select_lasso")
print("Switched to Lasso Selection Tool in 3D Viewport")
elif active_tool_id == 'builtin.select_lasso':
bpy.ops.wm.tool_set_by_id(name="builtin.select_box")
print("Switched to Box Selection Tool in 3D Viewport")
# Function to switch the active selection tool in Image Editor or UV Editor mode
def switch_selection_tool_image_editor():
# Get the current mode
mode = bpy.context.mode
# Get the active tool ID for UV Editor mode
active_tool_id = bpy.context.workspace.tools.from_space_uv_mode(mode, create=False).idname
# Switch selection tool based on the active tool ID
if active_tool_id == 'builtin.select_circle':
bpy.ops.wm.tool_set_by_id(name="builtin.select_box")
print("Switched to Box Selection Tool in UV Editor")
elif active_tool_id == 'builtin.select_box':
bpy.ops.wm.tool_set_by_id(name="builtin.select_lasso")
print("Switched to Lasso Selection Tool in UV Editor")
elif active_tool_id == 'builtin.select_lasso':
bpy.ops.wm.tool_set_by_id(name="builtin.select_box")
print("Switched to Box Selection Tool in UV Editor")
# Call the function to switch the selection tool
switch_selection_tool()