2019-03-14 14:15:29 +11:00
|
|
|
# This example adds an object mode tool to the toolbar.
|
|
|
|
# This is just the circle-select and lasso tools tool.
|
|
|
|
import bpy
|
|
|
|
from bpy.types import WorkSpaceTool
|
|
|
|
|
2019-10-15 15:20:15 +11:00
|
|
|
|
2019-03-14 14:15:29 +11:00
|
|
|
class MyTool(WorkSpaceTool):
|
2019-10-15 15:20:15 +11:00
|
|
|
bl_space_type = 'VIEW_3D'
|
|
|
|
bl_context_mode = 'OBJECT'
|
2019-03-14 14:15:29 +11:00
|
|
|
|
|
|
|
# The prefix of the idname should be your add-on name.
|
|
|
|
bl_idname = "my_template.my_circle_select"
|
|
|
|
bl_label = "My Circle Select"
|
|
|
|
bl_description = (
|
|
|
|
"This is a tooltip\n"
|
|
|
|
"with multiple lines"
|
|
|
|
)
|
|
|
|
bl_icon = "ops.generic.select_circle"
|
|
|
|
bl_widget = None
|
|
|
|
bl_keymap = (
|
|
|
|
("view3d.select_circle", {"type": 'LEFTMOUSE', "value": 'PRESS'},
|
|
|
|
{"properties": [("wait_for_input", False)]}),
|
|
|
|
("view3d.select_circle", {"type": 'LEFTMOUSE', "value": 'PRESS', "ctrl": True},
|
|
|
|
{"properties": [("mode", 'SUB'), ("wait_for_input", False)]}),
|
|
|
|
)
|
|
|
|
|
|
|
|
def draw_settings(context, layout, tool):
|
|
|
|
props = tool.operator_properties("view3d.select_circle")
|
|
|
|
layout.prop(props, "mode")
|
|
|
|
layout.prop(props, "radius")
|
|
|
|
|
|
|
|
|
|
|
|
class MyOtherTool(WorkSpaceTool):
|
2019-10-15 15:20:15 +11:00
|
|
|
bl_space_type = 'VIEW_3D'
|
|
|
|
bl_context_mode = 'OBJECT'
|
2019-03-14 14:15:29 +11:00
|
|
|
|
|
|
|
bl_idname = "my_template.my_other_select"
|
|
|
|
bl_label = "My Lasso Tool Select"
|
|
|
|
bl_description = (
|
|
|
|
"This is a tooltip\n"
|
|
|
|
"with multiple lines"
|
|
|
|
)
|
|
|
|
bl_icon = "ops.generic.select_lasso"
|
|
|
|
bl_widget = None
|
|
|
|
bl_keymap = (
|
|
|
|
("view3d.select_lasso", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None),
|
|
|
|
("view3d.select_lasso", {"type": 'LEFTMOUSE', "value": 'PRESS', "ctrl": True},
|
|
|
|
{"properties": [("mode", 'SUB')]}),
|
|
|
|
)
|
|
|
|
|
|
|
|
def draw_settings(context, layout, tool):
|
|
|
|
props = tool.operator_properties("view3d.select_lasso")
|
|
|
|
layout.prop(props, "mode")
|
|
|
|
|
|
|
|
|
2021-08-26 16:02:31 +10:00
|
|
|
class MyWidgetTool(WorkSpaceTool):
|
|
|
|
bl_space_type = 'VIEW_3D'
|
|
|
|
bl_context_mode = 'OBJECT'
|
|
|
|
|
|
|
|
bl_idname = "my_template.my_gizmo_translate"
|
|
|
|
bl_label = "My Gizmo Tool"
|
|
|
|
bl_description = "Short description"
|
|
|
|
bl_icon = "ops.transform.translate"
|
2022-04-20 15:11:22 +10:00
|
|
|
bl_widget = "VIEW3D_GGT_tool_generic_handle_free"
|
|
|
|
bl_widget_properties = [
|
2021-08-26 16:02:31 +10:00
|
|
|
("radius", 75.0),
|
|
|
|
("backdrop_fill_alpha", 0.0),
|
|
|
|
]
|
|
|
|
bl_keymap = (
|
|
|
|
("transform.translate", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None),
|
|
|
|
)
|
|
|
|
|
|
|
|
def draw_settings(context, layout, tool):
|
|
|
|
props = tool.operator_properties("transform.translate")
|
|
|
|
layout.prop(props, "mode")
|
|
|
|
|
|
|
|
|
2019-03-14 14:15:29 +11:00
|
|
|
def register():
|
|
|
|
bpy.utils.register_tool(MyTool, after={"builtin.scale_cage"}, separator=True, group=True)
|
|
|
|
bpy.utils.register_tool(MyOtherTool, after={MyTool.bl_idname})
|
2021-08-26 16:02:31 +10:00
|
|
|
bpy.utils.register_tool(MyWidgetTool, after={MyTool.bl_idname})
|
2019-03-14 14:15:29 +11:00
|
|
|
|
2019-10-15 15:20:15 +11:00
|
|
|
|
2019-03-14 14:15:29 +11:00
|
|
|
def unregister():
|
|
|
|
bpy.utils.unregister_tool(MyTool)
|
|
|
|
bpy.utils.unregister_tool(MyOtherTool)
|
2021-08-26 16:02:31 +10:00
|
|
|
bpy.utils.unregister_tool(MyWidgetTool)
|
2019-03-14 14:15:29 +11:00
|
|
|
|
2019-10-15 15:20:15 +11:00
|
|
|
|
2019-03-14 14:15:29 +11:00
|
|
|
if __name__ == "__main__":
|
|
|
|
register()
|