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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# gpl author: Stanislav Blinov
bl_info = {
"name": "V/E/F Context Menu",
"author": "Stanislav Blinov",
"version": (1, 0, 1),
"blender": (2, 78, 0),
"description": "Vert Edge Face Double Right Click Edit Mode",
"category": "Mesh",
}
import bpy
import bpy_extras
from bpy.types import (
Menu,
Operator,
)
class MESH_MT_CombinedMenu(Menu):
bl_idname = "mesh.addon_combined_component_menu"
bl_label = "Components"
@classmethod
def poll(cls, context):
return context.mode == 'EDIT_MESH'
def draw(self, context):
layout = self.layout
mode = context.tool_settings.mesh_select_mode
if mode[0]:
layout.menu("VIEW3D_MT_edit_mesh_vertices")
if mode[1]:
layout.menu("VIEW3D_MT_edit_mesh_edges")
if mode[2]:
layout.menu("VIEW3D_MT_edit_mesh_faces")
class MESH_OT_CallContextMenu(Operator):
bl_idname = "mesh.addon_call_context_menu"
bl_label = "Context Menu"
@classmethod
def poll(cls, context):
return context.mode == 'EDIT_MESH'
def execute(self, context):
mode = context.tool_settings.mesh_select_mode
num = sum(int(m) for m in mode)
if num == 1:
if mode[0]:
return bpy.ops.wm.call_menu(name="VIEW3D_MT_edit_mesh_vertices")
if mode[1]:
return bpy.ops.wm.call_menu(name="VIEW3D_MT_edit_mesh_edges")
if mode[2]:
return bpy.ops.wm.call_menu(name="VIEW3D_MT_edit_mesh_faces")
else:
return bpy.ops.wm.call_menu(name=MESH_MT_CombinedMenu.bl_idname)
classes = [
MESH_MT_CombinedMenu,
MESH_OT_CallContextMenu
]
KEYMAPS = (
# First, keymap identifiers (last bool is True for modal km).
(("3D View", "VIEW_3D", "WINDOW", False), (
# Then a tuple of keymap items, defined by a dict of kwargs for the km new func, and a tuple of tuples (name, val)
# for ops properties, if needing non-default values.
({"idname": MESH_OT_CallContextMenu.bl_idname, "type": 'RIGHTMOUSE', "value": 'DOUBLE_CLICK'},
()),
)),
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy_extras.keyconfig_utils.addon_keymap_register(bpy.context.window_manager, KEYMAPS)
def unregister():
bpy_extras.keyconfig_utils.addon_keymap_unregister(bpy.context.window_manager, KEYMAPS)
for cls in classes:
bpy.utils.unregister_class(cls)
if __name__ == "__main__":
register()
|