-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clear_all.py
122 lines (92 loc) · 3.72 KB
/
clear_all.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
122
# Thanks, Sybren
# https://www.youtube.com/watch?v=xscQ9tcN4GI&list=PLa1F2ddGya_8acrgoQr1fTeIuQtkSd6BW&index=3
import bpy
bl_info = {
"name": "Clear All Transforms",
"author": "Bent Hillerkus <[email protected]>",
"version": (1, 0, 1),
"blender": (2, 83, 0),
"category": "Object",
"location": "View3D > Object > Clear > Transforms",
"description": "Clear the location, rotation, the scale and the object origin. The default hotkey is Alt+T.",
"warning": "",
"doc_url": "https://github.com/benthillerkus/clear_all",
"tracker_url": "https://github.com/benthillerkus/clear_all/issues/new",
}
addon_keymaps = [] # This will keep track of our shortcuts so we can unregister them.
def register_shortcuts():
# Keymap code by Darkfall
# https://www.youtube.com/watch?v=0xBhh47Tblc
wm = bpy.context.window_manager
kc = wm.keyconfigs.addon
if kc:
km = kc.keymaps.new(name= '3D View', space_type= 'VIEW_3D')
kmi = km.keymap_items.new("object.transforms_clear", type= 'T', value= 'PRESS', alt= True)
addon_keymaps.append((km, kmi))
def unregister_shortcuts():
for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
addon_keymaps.clear()
def set_shortcuts(self, context):
if context.preferences.addons[__name__].preferences.shortcut:
register_shortcuts()
else:
unregister_shortcuts()
class Preferences(bpy.types.AddonPreferences):
bl_idname = __name__
shortcut: bpy.props.BoolProperty(
name ="Use default shortcut (Alt + T)",
default = True,
update = set_shortcuts
)
def draw(self, context):
self.layout.label(text= "If you already have a shortcut that uses Alt + T, you can disable the default shortcut.")
self.layout.label(text= "To set a custom shortcut, in the keymap editor for the 3D View, add an entry for the operator object.transforms.clear")
self.layout.prop(self, "shortcut")
class OBJECT_OT_clear_all_transforms(bpy.types.Operator):
"""Clear All Transforms"""
bl_idname = "object.transforms_clear"
bl_label = "Transforms"
bl_options = {'REGISTER', 'UNDO'}
location: bpy.props.BoolProperty(
name = "Location",
description = "Clear the location",
default = True
)
rotation: bpy.props.BoolProperty(
name = "Rotation",
description = "Clear the rotation",
default = True
)
scale: bpy.props.BoolProperty(
name = "Scale",
description = "Clear the scale",
default = True
)
delta: bpy.props.BoolProperty(
name = "Delta",
description = "Also clear the delta transforms",
default = False
)
@classmethod
def poll(cls, context):
return context.area.type == 'VIEW_3D' and context.mode == 'OBJECT'
def execute(self, context):
if self.location:
bpy.ops.object.location_clear(clear_delta= self.delta)
if self.rotation:
bpy.ops.object.rotation_clear(clear_delta= self.delta)
if self.scale:
bpy.ops.object.scale_clear(clear_delta= self.delta)
return {'FINISHED'}
def menu_draw(self, context):
self.layout.operator("object.transforms_clear")
bpy.types.VIEW3D_MT_object_clear.prepend(menu_draw)
def register():
bpy.utils.register_class(Preferences)
bpy.utils.register_class(OBJECT_OT_clear_all_transforms)
set_shortcuts(None, bpy.context)
def unregister():
unregister_shortcuts()
bpy.utils.unregister_class(OBJECT_OT_clear_all_transforms)
bpy.utils.unregister_class(Preferences)