-
Notifications
You must be signed in to change notification settings - Fork 4
/
extrude_menu.py
49 lines (33 loc) · 1.48 KB
/
extrude_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
from .Utils.core import *
class ExtrudeMenuOperator(bpy.types.Operator):
bl_label = "Extrude Menu Operator"
bl_idname = "view3d.extrude_menu_operator"
def modal(self, context, event):
current_time = time.time()
# if key has been held for more than 0.3 seconds call the menu
if event.value == 'RELEASE' and current_time > self.start_time + 0.3:
bpy.ops.wm.call_menu(name="VIEW3D_MT_edit_mesh_extrude")
return {'FINISHED'}
# else extrude the selection
elif event.value == 'RELEASE' and current_time < self.start_time + 0.3:
bpy.ops.view3d.edit_mesh_extrude_move_normal()
return {'FINISHED'}
else:
return {'RUNNING_MODAL'}
def execute(self, context):
self.start_time = time.time()
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
### ------------ New hotkeys and registration ------------ ###
addon_keymaps = []
def register():
# create the global hotkey
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name='Mesh')
kmi = km.keymap_items.new('view3d.extrude_menu_operator', 'E', 'PRESS')
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()