/
context_menu_toolset.py
81 lines (69 loc) · 1.91 KB
/
context_menu_toolset.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Original Question in BSE
# [Is there a way to create a loc/rot/scale shortcut in the context menu?]
# (https://blender.stackexchange.com/questions/190176/is-there-a-way-to-create-a-loc-rot-scale-shortcut-in-the-context-menu/)
import bpy
bl_info = {
"name": "Toolset in right click context menu",
"description": "This addon inject the toolset (move, transform, rotate. ..) in to right click menu inside View 3D space.",
"author": "hikariTW",
"version": (0, 1),
"blender": (2, 80, 0),
"location": "View3D",
"support": "TESTING",
"category": "Interface",
}
__toolset_list = {
"builtin.select": {
'text': "Tweak Select",
'icon': 'RESTRICT_SELECT_OFF'
},
"builtin.select_box": {
'text': "Select Box",
'icon': 'STICKY_UVS_LOC'
},
"builtin.cursor": {
'text': "Cursor",
'icon': 'CURSOR'
},
"Separator": None,
"builtin.move": {
'text': "Move",
'icon': 'VIEW_PAN'
},
"builtin.rotate": {
'text': "Rotate",
'icon': 'ORIENTATION_GIMBAL'
},
"builtin.scale": {
'text': "Scale",
'icon': 'SNAP_FACE_CENTER'
},
"builtin.transform": {
'text': "Transform",
'icon': 'PIVOT_CURSOR'
},
}
__context_menu_list = [
bpy.types.VIEW3D_MT_edit_mesh_context_menu,
bpy.types.VIEW3D_MT_object_context_menu,
]
def menu_func(self, context):
layout = self.layout
layout.label(text="Set Tool")
for key, content in __toolset_list.items():
if content:
layout.operator(
"WM_OT_tool_set_by_id",
**content
).name = key
else:
layout.separator()
layout.separator()
def register():
for menu in __context_menu_list:
menu.prepend(menu_func)
def unregister():
for menu in __context_menu_list:
menu.remove(menu_func)
if __name__ == "__main__":
register()