1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# 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
class MyTool(WorkSpaceTool):
bl_space_type='VIEW_3D'
bl_context_mode='OBJECT'
# 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):
bl_space_type='VIEW_3D'
bl_context_mode='OBJECT'
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")
def register():
bpy.utils.register_tool(MyTool, after={"builtin.scale_cage"}, separator=True, group=True)
bpy.utils.register_tool(MyOtherTool, after={MyTool.bl_idname})
def unregister():
bpy.utils.unregister_tool(MyTool)
bpy.utils.unregister_tool(MyOtherTool)
if __name__ == "__main__":
register()
|