-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathTopoShortcutBind.py
116 lines (85 loc) · 3.23 KB
/
TopoShortcutBind.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
bl_info = {
"name": "ShortcutTool",
"author": "Robert Fornof",
"version": (0, 5),
"blender": (2, 70, 0),
"location": "Check the shortcuts for dynamic topology ",
"description": "CTRL +SPACE toggles subdiv edges and collapse edges, hold down Q in sculpt to do the same",
"warning": "",
"wiki_url": "",
"category": "Object"}
import bpy
from bpy.app.handlers import persistent
def Press(self,context):
c = 'COLLAPSE'
context.tool_settings.sculpt.detail_refine_method = c
print("Pressed")
def Release(self,context):
s = 'SUBDIVIDE'
c = 'COLLAPSE'
context.tool_settings.sculpt.detail_refine_method = s
print("Released")
def Toggle(self,context):
s = 'SUBDIVIDE'
c = 'COLLAPSE'
context = bpy.context.scene
currentSetting = context.tool_settings.sculpt.detail_refine_method
if currentSetting == s:
context.tool_settings.sculpt.detail_refine_method = c
elif currentSetting == c:
context.tool_settings.sculpt.detail_refine_method = s
else:
context.tool_settings.sculpt.detail_refine_method = s #default
class TopoShortcutOn(bpy.types.Operator):
"""This Operator Add a Object to Another with Boolean Operations"""
bl_idname = "object.collapseon"
bl_label = "Topo Subdiv Toggle"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
print("Toggled")
Release(self,context)
return {'FINISHED'}
class TopoShortcutToggle(bpy.types.Operator):
"""This Operator Add a Object to Another with Boolean Operations"""
bl_idname = "object.collapseon"
bl_label = "Topo Subdiv Toggle"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
print("Toggled")
Toggle(self,context)
return {'FINISHED'}
class TopoShortcutOff(bpy.types.Operator):
"""This Operator Add a Object to Another with Boolean Operations"""
bl_idname = "object.collapseon"
bl_label = "Topo Subdiv Toggle"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
print("Toggled")
Release(self,context)
return {'FINISHED'}
def setTool(input):
context.tool_settings.sculpt.detail_refine_method = input
#------------------- REGISTER ------------------------------
addon_keymaps = []
def register():
bpy.utils.register_class(TopoShortcutOff)
bpy.utils.register_class(TopoShortcutOn)
bpy.utils.register_class(TopoShortcutToggle)
km = bpy.context.window_manager.keyconfigs.active.keymaps['Sculpt']
kmi = km.keymap_items.new(TopoShortcutOff.bl_idname, 'Q', 'PRESS', ctrl = False)
kmi = km.keymap_items.new(TopoShortcutOn.bl_idname, 'Q', 'RELEASE', ctrl = False)
kmi = km.keymap_items.new(TopoShortcutToggle.bl_idname, 'SPACE', 'RELEASE', ctrl = True)
def unregister():
bpy.utils.unregister_class(TopoShortcutOff)
bpy.utils.unregister_class(TopoShortcutOn)
for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
addon_keymaps.clear()
if __name__ == "__main__":
register()