forked from wheybags/freeablo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_menu.py
121 lines (88 loc) · 4.04 KB
/
delete_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
from .Utils.core import *
# adds a context sensitive delete menu
class DeleteMenu(bpy.types.Menu):
bl_label = "Delete"
bl_idname = "MESH_MT_context_delete_menu"
@classmethod
def poll(self, context):
if get_mode() == 'EDIT':
return True
else:
return False
def init(self):
sel_verts_num, sel_edges_num, sel_faces_num = get_selected()
if sel_verts_num and not sel_edges_num and not sel_faces_num:
selected = "verts"
elif sel_verts_num and sel_edges_num and not sel_faces_num:
selected = "edges"
elif sel_verts_num and sel_edges_num and sel_faces_num:
selected = "faces"
else:
selected = "none"
return selected
def draw(self, context):
menu = Menu(self)
selected = self.init()
if selected == "none":
menu.add_item().label("Nothing to Delete")
return
elif selected == "verts":
self.draw_verts(menu)
elif selected == "edges":
self.draw_edges(menu)
else:
self.draw_faces(menu)
def draw_verts(self, menu):
prop = menu.add_item().operator("mesh.delete", "Verts", icon='VERTEXSEL')
prop.type = 'VERT'
menu.add_item().operator("mesh.dissolve_verts", icon='SNAP_VERTEX')
menu.add_item().operator("mesh.dissolve_limited", icon='STICKY_UVS_LOC')
def draw_edges(self, menu):
prop = menu.add_item().operator("mesh.delete", "Verts", icon='VERTEXSEL')
prop.type = 'VERT'
prop = menu.add_item().operator("mesh.delete", "Edges", icon='EDGESEL')
prop.type = 'EDGE'
prop = menu.add_item().operator("mesh.delete", "Only Edges & Faces", icon='SPACE2')
prop.type = 'EDGE_FACE'
menu.add_item().separator()
menu.add_item().operator("mesh.dissolve_verts", icon='SNAP_VERTEX')
menu.add_item().operator("mesh.dissolve_edges", icon='SNAP_EDGE')
menu.add_item().separator()
menu.add_item().operator("mesh.dissolve_limited", icon='STICKY_UVS_LOC')
menu.add_item().separator()
menu.add_item().operator("mesh.delete_edgeloop", icon='BORDER_LASSO')
menu.add_item().operator("mesh.edge_collapse", icon='UV_EDGESEL')
def draw_faces(self, menu):
prop = menu.add_item().operator("mesh.delete", "Verts", icon='VERTEXSEL')
prop.type = 'VERT'
prop = menu.add_item().operator("mesh.delete", "Edges", icon='EDGESEL')
prop.type = 'EDGE'
prop = menu.add_item().operator("mesh.delete", "Faces", icon='FACESEL')
prop.type = 'FACE'
prop = menu.add_item().operator("mesh.delete", "Only Edges & Faces", icon='SPACE2')
prop.type = 'EDGE_FACE'
prop = menu.add_item().operator("mesh.delete", "Only Faces", icon='UV_FACESEL')
prop.type = 'ONLY_FACE'
menu.add_item().separator()
menu.add_item().operator("mesh.dissolve_verts", icon='SNAP_VERTEX')
menu.add_item().operator("mesh.dissolve_edges", icon='SNAP_EDGE')
menu.add_item().operator("mesh.dissolve_faces", icon='SNAP_FACE')
menu.add_item().separator()
menu.add_item().operator("mesh.dissolve_limited", icon='STICKY_UVS_LOC')
menu.add_item().separator()
menu.add_item().operator("mesh.delete_edgeloop", icon='BORDER_LASSO')
menu.add_item().operator("mesh.edge_collapse", icon='UV_EDGESEL')
### ------------ New hotkeys and registration ------------ ###
addon_keymaps = []
def register():
# create the global menu hotkey
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name='Mesh')
kmi = km.keymap_items.new('wm.call_menu', 'X', 'PRESS')
kmi.properties.name = 'MESH_MT_context_delete_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()