Update addons for changes to proportional edit mode
[blender-addons.git] / space_view3d_pie_menus / pie_apply_transform_menu.py
blob35f99c52e1a95fd3fc54c4b635cc2c323922e9e8
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 # <pep8 compliant>
21 bl_info = {
22 "name": "Hotkey: 'Ctrl A'",
23 "description": "Apply Transform Menu",
24 "author": "pitiwazou, meta-androcto",
25 "version": (0, 1, 1),
26 "blender": (2, 80, 0),
27 "location": "3D View",
28 "warning": "",
29 "wiki_url": "",
30 "category": "Apply Transform Pie"
33 import bpy
34 from bpy.types import (
35 Menu,
36 Operator,
38 from bpy.props import EnumProperty
41 # Pie Apply Transforms - Ctrl + A
42 class PieApplyTransforms(Menu):
43 bl_idname = "PIE_MT_applytransforms"
44 bl_label = "Pie Apply Transforms"
46 def draw(self, context):
47 layout = self.layout
48 pie = layout.menu_pie()
49 # 4 - LEFT
50 pie.operator("apply.transformall", text="Apply All", icon='FREEZE')
51 # 6 - RIGHT
52 pie.operator("clear.all", text="Clear All", icon='NONE')
53 # 2 - BOTTOM
54 pie.operator("object.duplicates_make_real", text="Make Duplicates Real")
55 # 8 - TOP
56 pie.operator("apply.transformlocrotscale", text="Rotation", icon='NONE').option = 'ROT'
57 # 7 - TOP - LEFT
58 pie.operator("apply.transformlocrotscale", text="Location", icon='NONE').option = 'LOC'
59 # 9 - TOP - RIGHT
60 pie.operator("apply.transformlocrotscale", text="Scale", icon='NONE').option = 'SCALE'
61 # 1 - BOTTOM - LEFT
62 pie.operator("object.visual_transform_apply", text="Visual Transforms")
63 # 3 - BOTTOM - RIGHT
64 pie.menu("PIE_MT_clear_menu", text="Clear Transform Menu")
67 # Apply Transforms
68 class ApplyTransLocRotPie(Operator):
69 bl_idname = "apply.transformlocrotscale"
70 bl_label = "Apply Transforms"
71 bl_description = "Apply Transform: Location, Rotation or Scale"
72 bl_options = {'REGISTER', 'UNDO'}
74 option: EnumProperty(
75 name="Type",
76 items=[
77 ("LOC", "Location", "Apply Location"),
78 ("ROT", "Rotation", "Apply Rotation"),
79 ("SCALE", "Scale", "Apply Scale")
81 default="LOC",
84 def execute(self, context):
85 loc = True if self.option == "LOC" else False
86 rot = True if self.option == "ROT" else False
87 sca = True if self.option == "SCALE" else False
88 bpy.ops.object.transform_apply(location=loc, rotation=rot, scale=sca)
90 return {'FINISHED'}
93 # Apply Transforms
94 class ApplyTransformAll(Operator):
95 bl_idname = "apply.transformall"
96 bl_label = "Apply All Transforms"
97 bl_description = "Apply Transform All"
98 bl_options = {'REGISTER', 'UNDO'}
100 def execute(self, context):
101 bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
102 return {'FINISHED'}
105 # Clear Menu
106 class ClearMenu(Menu):
107 bl_idname = "PIE_MT_clear_menu"
108 bl_label = "Clear Menu"
110 def draw(self, context):
111 layout = self.layout
112 layout.operator("object.location_clear", text="Clear Location", icon='NONE')
113 layout.operator("object.rotation_clear", text="Clear Rotation", icon='NONE')
114 layout.operator("object.scale_clear", text="Clear Scale", icon='NONE')
115 layout.operator("object.origin_clear", text="Clear Origin", icon='NONE')
118 # Clear all
119 class ClearAll(Operator):
120 bl_idname = "clear.all"
121 bl_label = "Clear All"
122 bl_description = "Clear All Transforms"
123 bl_options = {'REGISTER', 'UNDO'}
125 def execute(self, context):
126 bpy.ops.object.location_clear()
127 bpy.ops.object.rotation_clear()
128 bpy.ops.object.scale_clear()
129 return {'FINISHED'}
132 classes = (
133 PieApplyTransforms,
134 ApplyTransLocRotPie,
135 ApplyTransformAll,
136 ClearMenu,
137 ClearAll,
140 addon_keymaps = []
143 def register():
144 for cls in classes:
145 bpy.utils.register_class(cls)
146 wm = bpy.context.window_manager
148 if wm.keyconfigs.addon:
149 # Apply Transform
150 km = wm.keyconfigs.addon.keymaps.new(name='Object Mode')
151 kmi = km.keymap_items.new('wm.call_menu_pie', 'A', 'PRESS', ctrl=True)
152 kmi.properties.name = "PIE_MT_applytransforms"
153 addon_keymaps.append((km, kmi))
156 def unregister():
157 for cls in classes:
158 bpy.utils.unregister_class(cls)
160 wm = bpy.context.window_manager
161 kc = wm.keyconfigs.addon
162 if kc:
163 for km, kmi in addon_keymaps:
164 km.keymap_items.remove(kmi)
165 addon_keymaps.clear()
168 if __name__ == "__main__":
169 register()