Fix T99542: 3D print toolbox thickness check causes assertion
[blender-addons.git] / space_view3d_pie_menus / pie_align_menu.py
blob4ba1553e9114167fd0711d17a8fc81e95f3ded7f
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 bl_info = {
4 "name": "Hotkey: 'Alt X'",
5 "description": "V/E/F Align tools",
6 "author": "pitiwazou, meta-androcto",
7 "version": (0, 1, 2),
8 "blender": (2, 80, 0),
9 "location": "Mesh Edit Mode",
10 "warning": "",
11 "doc_url": "",
12 "category": "Edit Align Pie"
15 import bpy
16 from bpy.types import (
17 Menu,
18 Operator,
20 from bpy.props import EnumProperty
23 # Pie Align - Alt + X
24 class PIE_MT_Align(Menu):
25 bl_idname = "PIE_MT_align"
26 bl_label = "Pie Align"
28 def draw(self, context):
29 layout = self.layout
30 pie = layout.menu_pie()
31 # 4 - LEFT
32 box = pie.split().box().column()
34 row = box.row(align=True)
35 row.label(text="X")
36 align_1 = row.operator("alignxyz.all", text="Neg")
37 align_1.axis = '0'
38 align_1.side = 'NEGATIVE'
40 row = box.row(align=True)
41 row.label(text="Y")
42 align_3 = row.operator("alignxyz.all", text="Neg")
43 align_3.axis = '1'
44 align_3.side = 'NEGATIVE'
46 row = box.row(align=True)
47 row.label(text="Z")
48 align_5 = row.operator("alignxyz.all", text="Neg")
49 align_5.axis = '2'
50 align_5.side = 'NEGATIVE'
51 # 6 - RIGHT
52 box = pie.split().box().column()
54 row = box.row(align=True)
55 row.label(text="X")
56 align_2 = row.operator("alignxyz.all", text="Pos")
57 align_2.axis = '0'
58 align_2.side = 'POSITIVE'
60 row = box.row(align=True)
61 row.label(text="Y")
62 align_4 = row.operator("alignxyz.all", text="Pos")
63 align_4.axis = '1'
64 align_4.side = 'POSITIVE'
66 row = box.row(align=True)
67 row.label(text="Z")
68 align_6 = row.operator("alignxyz.all", text="Pos")
69 align_6.axis = '2'
70 align_6.side = 'POSITIVE'
71 # 2 - BOTTOM
72 pie.operator("align.2xyz", text="Align To Y-0").axis = '1'
73 # 8 - TOP
74 pie.operator("align.selected2xyz",
75 text="Align Y").axis = 'Y'
76 # 7 - TOP - LEFT
77 pie.operator("align.selected2xyz",
78 text="Align X").axis = 'X'
79 # 9 - TOP - RIGHT
80 pie.operator("align.selected2xyz",
81 text="Align Z").axis = 'Z'
82 # 1 - BOTTOM - LEFT
83 pie.operator("align.2xyz", text="Align To X-0").axis = '0'
84 # 3 - BOTTOM - RIGHT
85 pie.operator("align.2xyz", text="Align To Z-0").axis = '2'
88 # Align to X, Y, Z
89 class PIE_OT_AlignSelectedXYZ(Operator):
90 bl_idname = "align.selected2xyz"
91 bl_label = "Align to X, Y, Z"
92 bl_description = "Align Selected Along the chosen axis"
93 bl_options = {'REGISTER', 'UNDO'}
95 axis: EnumProperty(
96 name="Axis",
97 items=[
98 ('X', "X", "X Axis"),
99 ('Y', "Y", "Y Axis"),
100 ('Z', "Z", "Z Axis")
102 description="Choose an axis for alignment",
103 default='X'
106 @classmethod
107 def poll(cls, context):
108 obj = context.active_object
109 return obj and obj.type == "MESH"
111 def execute(self, context):
112 values = {
113 'X': [(0, 1, 1), (True, False, False)],
114 'Y': [(1, 0, 1), (False, True, False)],
115 'Z': [(1, 1, 0), (False, False, True)]
117 chosen_value = values[self.axis][0]
118 constraint_value = values[self.axis][1]
119 bpy.ops.transform.resize(
120 value=chosen_value,
121 constraint_axis=constraint_value,
122 orient_type='GLOBAL',
123 mirror=False,
124 use_proportional_edit=False,
126 return {'FINISHED'}
129 # ################# #
130 # Align To 0 #
131 # ################# #
133 class PIE_OT_AlignToXYZ0(Operator):
134 bl_idname = "align.2xyz"
135 bl_label = "Align To X, Y or Z = 0"
136 bl_description = "Align Active Object To a chosen X, Y or Z equals 0 Location"
137 bl_options = {'REGISTER', 'UNDO'}
139 axis: EnumProperty(
140 name="Axis",
141 items=[
142 ('0', "X", "X Axis"),
143 ('1', "Y", "Y Axis"),
144 ('2', "Z", "Z Axis")
146 description="Choose an axis for alignment",
147 default='0'
150 @classmethod
151 def poll(cls, context):
152 obj = context.active_object
153 return obj and obj.type == "MESH"
155 def execute(self, context):
156 bpy.ops.object.mode_set(mode='OBJECT')
157 align = int(self.axis)
158 for vert in bpy.context.object.data.vertices:
159 if vert.select:
160 vert.co[align] = 0
161 bpy.ops.object.editmode_toggle()
163 return {'FINISHED'}
166 # Align X Left
167 class PIE_OT_AlignXYZAll(Operator):
168 bl_idname = "alignxyz.all"
169 bl_label = "Align to Front/Back Axis"
170 bl_description = "Align to a Front or Back along the chosen Axis"
171 bl_options = {'REGISTER', 'UNDO'}
173 axis: EnumProperty(
174 name="Axis",
175 items=[
176 ('0', "X", "X Axis"),
177 ('1', "Y", "Y Axis"),
178 ('2', "Z", "Z Axis")
180 description="Choose an axis for alignment",
181 default='0'
183 side: EnumProperty(
184 name="Side",
185 items=[
186 ('POSITIVE', "Front", "Align on the positive chosen axis"),
187 ('NEGATIVE', "Back", "Align acriss the negative chosen axis"),
189 description="Choose a side for alignment",
190 default='POSITIVE'
193 @classmethod
194 def poll(cls, context):
195 obj = context.active_object
196 return obj and obj.type == "MESH"
198 def execute(self, context):
200 bpy.ops.object.mode_set(mode='OBJECT')
201 count = 0
202 axe = int(self.axis)
203 for vert in bpy.context.object.data.vertices:
204 if vert.select:
205 if count == 0:
206 maxv = vert.co[axe]
207 count += 1
208 continue
209 count += 1
210 if self.side == 'POSITIVE':
211 if vert.co[axe] > maxv:
212 maxv = vert.co[axe]
213 else:
214 if vert.co[axe] < maxv:
215 maxv = vert.co[axe]
217 bpy.ops.object.mode_set(mode='OBJECT')
219 for vert in bpy.context.object.data.vertices:
220 if vert.select:
221 vert.co[axe] = maxv
222 bpy.ops.object.mode_set(mode='EDIT')
224 return {'FINISHED'}
227 classes = (
228 PIE_MT_Align,
229 PIE_OT_AlignSelectedXYZ,
230 PIE_OT_AlignToXYZ0,
231 PIE_OT_AlignXYZAll,
234 addon_keymaps = []
237 def register():
238 for cls in classes:
239 bpy.utils.register_class(cls)
241 wm = bpy.context.window_manager
242 if wm.keyconfigs.addon:
243 # Align
244 km = wm.keyconfigs.addon.keymaps.new(name='Mesh')
245 kmi = km.keymap_items.new('wm.call_menu_pie', 'X', 'PRESS', alt=True)
246 kmi.properties.name = "PIE_MT_align"
247 addon_keymaps.append((km, kmi))
250 def unregister():
251 for cls in classes:
252 bpy.utils.unregister_class(cls)
254 wm = bpy.context.window_manager
255 kc = wm.keyconfigs.addon
256 if kc:
257 for km, kmi in addon_keymaps:
258 km.keymap_items.remove(kmi)
259 addon_keymaps.clear()
262 if __name__ == "__main__":
263 register()