-
Notifications
You must be signed in to change notification settings - Fork 3
/
selection_menu.py
72 lines (53 loc) · 2.45 KB
/
selection_menu.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
from .Utils.core import *
class SelectionModeMenu(bpy.types.Menu):
bl_label = "Select Mode"
bl_idname = "VIEW3D_MT_selection_menu"
@classmethod
def poll(self, context):
if get_mode() in [edit, particle_edit] and bpy.context.object.type == 'MESH':
return True
else:
return False
def init(self):
if get_mode() == edit:
modes = [["Vertex Select", (True, False, False), 'VERTEXSEL'],
["Edge Select", (False, True, False), 'EDGESEL'],
["Face Select", (False, False, True), 'FACESEL'],
["Vertex & Edge Select", (True, True, False), 'EDIT'],
["Vertex & Face Select", (True, False, True), 'EDITMODE_HLT'],
["Edge & Face Select", (False, True, True), 'SPACE2'],
["Vertex, Edge & Face Select", (True, True, True), 'OBJECT_DATAMODE']]
datapath = "tool_settings.mesh_select_mode[0:3]"
else:
modes = [["Path", 'PATH', 'PARTICLE_PATH'],
["Point", 'POINT', 'PARTICLE_POINT'],
["Tip", 'TIP', 'PARTICLE_TIP']]
datapath = "tool_settings.particle_edit.select_mode"
return modes, datapath
def draw(self, context):
modes, datapath = self.init()
menu = Menu(self)
for num, mode in enumerate(modes):
# add the items to the menu
menuprop(menu.add_item(), mode[0], mode[1], datapath,
icon=mode[2], disable=True)
# add a separator after each section
if num in [2, 6, 7]:
menu.add_item().separator()
menu.add_item().prop(context.space_data, "use_occlude_geometry", icon='ORTHO', toggle=True)
### ------------ New hotkeys and registration ------------ ###
addon_keymaps = []
def register():
# create the global hotkey
wm = bpy.context.window_manager
modes = ['Mesh', 'Particle']
for mode in modes:
km = wm.keyconfigs.addon.keymaps.new(name=mode)
kmi = km.keymap_items.new('wm.call_menu', 'TAB', 'PRESS', ctrl=True)
kmi.properties.name = 'VIEW3D_MT_selection_menu'
addon_keymaps.append((km, kmi))
def unregister():
# remove keymaps when add-on is deactivated
for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
addon_keymaps.clear()