~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to release/scripts/addons_contrib/space_view3d_simple_align.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-05-12 20:02:22 UTC
  • mfrom: (14.2.16 sid)
  • Revision ID: package-import@ubuntu.com-20120512200222-lznjs2cxzaq96wua
Tags: 2.63a-1
* New upstream bugfix release
  + debian/patches/: re-worked since source code changed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# AlingTools.py (c) 2009, 2010 Gabriel Beaudin (gabhead)
2
 
#
3
 
# ***** BEGIN GPL LICENSE BLOCK *****
4
 
#
5
 
#
6
 
# This program is free software; you can redistribute it and/or
7
 
# modify it under the terms of the GNU General Public License
8
 
# as published by the Free Software Foundation; either version 2
9
 
# of the License, or (at your option) any later version.
10
 
#
11
 
# This program is distributed in the hope that it will be useful,
12
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
# GNU General Public License for more details.
15
 
#
16
 
# You should have received a copy of the GNU General Public License
17
 
# along with this program; if not, write to the Free Software Foundation,
18
 
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 
#
20
 
# ***** END GPL LICENCE BLOCK *****
21
 
 
22
 
bl_info = {
23
 
    "name": "Simple Align",
24
 
    "author": "Gabriel Beaudin (gabhead)",
25
 
    "version": (0,1),
26
 
    "blender": (2, 6, 1),
27
 
    "location": "View3D > Tool Shelf > Simple Align Panel",
28
 
    "description": "Align Selected Objects to Active Object",
29
 
    "warning": "",
30
 
    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
31
 
        "Scripts/3D interaction/Align_Tools",
32
 
    "tracker_url": "https://projects.blender.org/tracker/index.php?"\
33
 
        "func=detail&aid==22389",
34
 
    "category": "3D View"}
35
 
 
36
 
"""Align Selected Objects"""
37
 
 
38
 
import bpy
39
 
 
40
 
 
41
 
class AlignUi(bpy.types.Panel):
42
 
    bl_space_type = 'VIEW_3D'
43
 
    bl_region_type = 'TOOLS'
44
 
 
45
 
    bl_label = "Simple Align"
46
 
    bl_context = "objectmode"
47
 
 
48
 
    def draw(self, context):
49
 
        layout = self.layout
50
 
        obj = context.object
51
 
 
52
 
        if obj != None:
53
 
            row = layout.row()
54
 
            row.label(text="Active object is: ", icon='OBJECT_DATA')
55
 
            row = layout.row()
56
 
            row.label(obj.name, icon='EDITMODE_HLT')
57
 
        
58
 
        layout.separator()
59
 
        
60
 
        col = layout.column()
61
 
        col.label(text="Align Loc + Rot:", icon='MANIPUL')
62
 
 
63
 
        
64
 
        col = layout.column(align=False)
65
 
        col.operator("object.align",text="XYZ")
66
 
        
67
 
        col = layout.column()
68
 
        col.label(text="Align Location:", icon='MAN_TRANS')
69
 
 
70
 
        col = layout.column_flow(columns=5,align=True)
71
 
        col.operator("object.align_location_x",text="X")
72
 
        col.operator("object.align_location_y",text="Y")
73
 
        col.operator("object.align_location_z",text="Z")
74
 
        col.operator("object.align_location_all",text="All")
75
 
 
76
 
        col = layout.column()
77
 
        col.label(text="Align Rotation:", icon='MAN_ROT')
78
 
 
79
 
        col = layout.column_flow(columns=5,align=True)
80
 
        col.operator("object.align_rotation_x",text="X")
81
 
        col.operator("object.align_rotation_y",text="Y")
82
 
        col.operator("object.align_rotation_z",text="Z")
83
 
        col.operator("object.align_rotation_all",text="All")
84
 
        
85
 
        col = layout.column()
86
 
        col.label(text="Align Scale:", icon='MAN_SCALE')
87
 
 
88
 
        col = layout.column_flow(columns=5,align=True)
89
 
        col.operator("object.align_objects_scale_x",text="X")
90
 
        col.operator("object.align_objects_scale_y",text="Y")
91
 
        col.operator("object.align_objects_scale_z",text="Z")
92
 
        col.operator("object.align_objects_scale_all",text="All")
93
 
 
94
 
 
95
 
##Align all
96
 
def main(context):
97
 
    for i in bpy.context.selected_objects:
98
 
        i.location = bpy.context.active_object.location
99
 
        i.rotation_euler = bpy.context.active_object.rotation_euler
100
 
 
101
 
## Align Location
102
 
 
103
 
def LocAll(context):
104
 
    for i in bpy.context.selected_objects:
105
 
        i.location = bpy.context.active_object.location
106
 
 
107
 
def LocX(context):
108
 
    for i in bpy.context.selected_objects:
109
 
        i.location.x = bpy.context.active_object.location.x
110
 
 
111
 
def LocY(context):
112
 
    for i in bpy.context.selected_objects:
113
 
        i.location.y = bpy.context.active_object.location.y
114
 
 
115
 
def LocZ(context):
116
 
    for i in bpy.context.selected_objects:
117
 
        i.location.z = bpy.context.active_object.location.z
118
 
 
119
 
## Aling Rotation
120
 
def RotAll(context):
121
 
    for i in bpy.context.selected_objects:
122
 
        i.rotation_euler = bpy.context.active_object.rotation_euler
123
 
 
124
 
def RotX(context):
125
 
    for i in bpy.context.selected_objects:
126
 
        i.rotation_euler.x = bpy.context.active_object.rotation_euler.x
127
 
 
128
 
def RotY(context):
129
 
    for i in bpy.context.selected_objects:
130
 
        i.rotation_euler.y = bpy.context.active_object.rotation_euler.y
131
 
 
132
 
def RotZ(context):
133
 
    for i in bpy.context.selected_objects:
134
 
        i.rotation_euler.z = bpy.context.active_object.rotation_euler.z
135
 
## Aling Scale
136
 
def ScaleAll(context):
137
 
    for i in bpy.context.selected_objects:
138
 
        i.scale = bpy.context.active_object.scale
139
 
 
140
 
def ScaleX(context):
141
 
    for i in bpy.context.selected_objects:
142
 
        i.scale.x = bpy.context.active_object.scale.x
143
 
 
144
 
def ScaleY(context):
145
 
    for i in bpy.context.selected_objects:
146
 
        i.scale.y = bpy.context.active_object.scale.y
147
 
 
148
 
def ScaleZ(context):
149
 
    for i in bpy.context.selected_objects:
150
 
        i.scale.z = bpy.context.active_object.scale.z
151
 
 
152
 
## Classes
153
 
 
154
 
## Align All Rotation And Location
155
 
class AlignOperator(bpy.types.Operator):
156
 
    ''''''
157
 
    bl_idname = "object.align"
158
 
    bl_label = "Align Selected To Active"
159
 
 
160
 
    @classmethod
161
 
    def poll(cls, context):
162
 
        return context.active_object != None
163
 
 
164
 
    def execute(self, context):
165
 
        main(context)
166
 
        return {'FINISHED'}
167
 
 
168
 
#######################Align Location########################
169
 
## Align LocationAll
170
 
class AlignLocationOperator(bpy.types.Operator):
171
 
    ''''''
172
 
    bl_idname = "object.align_location_all"
173
 
    bl_label = "Align Selected Location To Active"
174
 
 
175
 
    @classmethod
176
 
    def poll(cls, context):
177
 
        return context.active_object != None
178
 
 
179
 
    def execute(self, context):
180
 
        LocAll(context)
181
 
        return {'FINISHED'}
182
 
## Align LocationX
183
 
class AlignLocationXOperator(bpy.types.Operator):
184
 
    ''''''
185
 
    bl_idname = "object.align_location_x"
186
 
    bl_label = "Align Selected Location X To Active"
187
 
 
188
 
    @classmethod
189
 
    def poll(cls, context):
190
 
        return context.active_object != None
191
 
 
192
 
    def execute(self, context):
193
 
        LocX(context)
194
 
        return {'FINISHED'}
195
 
## Align LocationY
196
 
class AlignLocationYOperator(bpy.types.Operator):
197
 
    ''''''
198
 
    bl_idname = "object.align_location_y"
199
 
    bl_label = "Align Selected Location Y To Active"
200
 
 
201
 
    @classmethod
202
 
    def poll(cls, context):
203
 
        return context.active_object != None
204
 
 
205
 
    def execute(self, context):
206
 
        LocY(context)
207
 
        return {'FINISHED'}
208
 
## Align LocationZ
209
 
class AlignLocationZOperator(bpy.types.Operator):
210
 
    ''''''
211
 
    bl_idname = "object.align_location_z"
212
 
    bl_label = "Align Selected Location Z To Active"
213
 
 
214
 
    @classmethod
215
 
    def poll(cls, context):
216
 
        return context.active_object != None
217
 
 
218
 
    def execute(self, context):
219
 
        LocZ(context)
220
 
        return {'FINISHED'}
221
 
 
222
 
#######################Align Rotation########################
223
 
## Align RotationAll
224
 
class AlignRotationOperator(bpy.types.Operator):
225
 
    ''''''
226
 
    bl_idname = "object.align_rotation_all"
227
 
    bl_label = "Align Selected Rotation To Active"
228
 
 
229
 
    @classmethod
230
 
    def poll(cls, context):
231
 
        return context.active_object != None
232
 
 
233
 
    def execute(self, context):
234
 
        RotAll(context)
235
 
        return {'FINISHED'}
236
 
## Align RotationX
237
 
class AlignRotationXOperator(bpy.types.Operator):
238
 
    ''''''
239
 
    bl_idname = "object.align_rotation_x"
240
 
    bl_label = "Align Selected Rotation X To Active"
241
 
 
242
 
    @classmethod
243
 
    def poll(cls, context):
244
 
        return context.active_object != None
245
 
 
246
 
    def execute(self, context):
247
 
        RotX(context)
248
 
        return {'FINISHED'}
249
 
## Align RotationY
250
 
class AlignRotationYOperator(bpy.types.Operator):
251
 
    ''''''
252
 
    bl_idname = "object.align_rotation_y"
253
 
    bl_label = "Align Selected Rotation Y To Active"
254
 
 
255
 
    @classmethod
256
 
    def poll(cls, context):
257
 
        return context.active_object != None
258
 
 
259
 
    def execute(self, context):
260
 
        RotY(context)
261
 
        return {'FINISHED'}
262
 
## Align RotationZ
263
 
class AlignRotationZOperator(bpy.types.Operator):
264
 
    ''''''
265
 
    bl_idname = "object.align_rotation_z"
266
 
    bl_label = "Align Selected Rotation Z To Active"
267
 
 
268
 
    @classmethod
269
 
    def poll(cls, context):
270
 
        return context.active_object != None
271
 
 
272
 
    def execute(self, context):
273
 
        RotZ(context)
274
 
        return {'FINISHED'}
275
 
#######################Align Scale########################
276
 
## Scale All
277
 
class AlignScaleOperator(bpy.types.Operator):
278
 
    ''''''
279
 
    bl_idname = "object.align_objects_scale_all"
280
 
    bl_label = "Align Selected Scale To Active"
281
 
 
282
 
    @classmethod
283
 
    def poll(cls, context):
284
 
        return context.active_object != None
285
 
 
286
 
    def execute(self, context):
287
 
        ScaleAll(context)
288
 
        return {'FINISHED'}
289
 
## Align ScaleX
290
 
class AlignScaleXOperator(bpy.types.Operator):
291
 
    ''''''
292
 
    bl_idname = "object.align_objects_scale_x"
293
 
    bl_label = "Align Selected Scale X To Active"
294
 
 
295
 
    @classmethod
296
 
    def poll(cls, context):
297
 
        return context.active_object != None
298
 
 
299
 
    def execute(self, context):
300
 
        ScaleX(context)
301
 
        return {'FINISHED'}
302
 
## Align ScaleY
303
 
class AlignScaleYOperator(bpy.types.Operator):
304
 
    ''''''
305
 
    bl_idname = "object.align_objects_scale_y"
306
 
    bl_label = "Align Selected Scale Y To Active"
307
 
 
308
 
    @classmethod
309
 
    def poll(cls, context):
310
 
        return context.active_object != None
311
 
 
312
 
    def execute(self, context):
313
 
        ScaleY(context)
314
 
        return {'FINISHED'}
315
 
## Align ScaleZ
316
 
class AlignScaleZOperator(bpy.types.Operator):
317
 
    ''''''
318
 
    bl_idname = "object.align_objects_scale_z"
319
 
    bl_label = "Align Selected Scale Z To Active"
320
 
 
321
 
    @classmethod
322
 
    def poll(cls, context):
323
 
        return context.active_object != None
324
 
 
325
 
    def execute(self, context):
326
 
        ScaleZ(context)
327
 
        return {'FINISHED'}
328
 
 
329
 
## registring
330
 
def register():
331
 
    bpy.utils.register_module(__name__)
332
 
 
333
 
    pass
334
 
 
335
 
def unregister():
336
 
    bpy.utils.unregister_module(__name__)
337
 
 
338
 
    pass
339
 
 
340
 
if __name__ == "__main__":
341
 
    register()