Welcome to mirror list, hosted at ThFree Co, Russian Federation.

space_view3d_align_tools.py - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 735c5b3127419698760c0e1544b02e6efe407614 (plain)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# AlingTools.py (c) 2009, 2010 Gabriel Beaudin (gabhead)
#
# ***** BEGIN GPL LICENSE BLOCK *****
#
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ***** END GPL LICENCE BLOCK *****

bl_addon_info = {
    "name": "Align Tools",
    "author": "Gabriel Beaudin (gabhead)",
    "version": (0,1),
    "blender": (2, 5, 3),
    "api": 32411,
    "location": "Tool Shelf",
    "description": "Align selected objects to the active object",
    "warning": "",
    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
        "Scripts/3D interaction/Align_Tools",
    "tracker_url": "https://projects.blender.org/tracker/index.php?"\
        "func=detail&aid==22389&group_id=153&atid=468",
    "category": "3D View"}

"""Align Selected Objects"""

import bpy


class AlignUi(bpy.types.Panel):
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'

    bl_label = "Align Tools"
    bl_context = "objectmode"

    def draw(self, context):
        layout = self.layout
        obj = context.object

        if obj != None:
            row = layout.row()
            row.label(text="Active object is: ", icon='OBJECT_DATA')
            row = layout.row()
            row.label(obj.name, icon='EDITMODE_HLT')
        
        box = layout.separator()
        
        col = layout.column()
        col.label(text="Align Loc + Rot:", icon='MANIPUL')

        
        col = layout.column(align=False)
        col.operator("object.AlignObjects",text="XYZ")
        
        col = layout.column()
        col.label(text="Align Location:", icon='MAN_TRANS')

        col = layout.column_flow(columns=5,align=True)
        col.operator("object.AlignObjectsLocationX",text="X")
        col.operator("object.AlignObjectsLocationY",text="Y")
        col.operator("object.AlignObjectsLocationZ",text="Z")
        col.operator("object.AlignObjectsLocationAll",text="All")

        col = layout.column()
        col.label(text="Align Rotation:", icon='MAN_ROT')

        col = layout.column_flow(columns=5,align=True)
        col.operator("object.AlignObjectsRotationX",text="X")
        col.operator("object.AlignObjectsRotationY",text="Y")
        col.operator("object.AlignObjectsRotationZ",text="Z")
        col.operator("object.AlignObjectsRotationAll",text="All")
        
        col = layout.column()
        col.label(text="Align Scale:", icon='MAN_SCALE')

        col = layout.column_flow(columns=5,align=True)
        col.operator("object.AlignObjectsScaleX",text="X")
        col.operator("object.AlignObjectsScaleY",text="Y")
        col.operator("object.AlignObjectsScaleZ",text="Z")
        col.operator("object.AlignObjectsScaleAll",text="All")


##Align all
def main(context):
    for i in bpy.context.selected_objects:
        i.location = bpy.context.active_object.location
        i.rotation_euler = bpy.context.active_object.rotation_euler

## Align Location

def LocAll(context):
    for i in bpy.context.selected_objects:
        i.location = bpy.context.active_object.location

def LocX(context):
    for i in bpy.context.selected_objects:
        i.location.x = bpy.context.active_object.location.x

def LocY(context):
    for i in bpy.context.selected_objects:
        i.location.y = bpy.context.active_object.location.y

def LocZ(context):
    for i in bpy.context.selected_objects:
        i.location.z = bpy.context.active_object.location.z

## Aling Rotation
def RotAll(context):
    for i in bpy.context.selected_objects:
        i.rotation_euler = bpy.context.active_object.rotation_euler

def RotX(context):
    for i in bpy.context.selected_objects:
        i.rotation_euler.x = bpy.context.active_object.rotation_euler.x

def RotY(context):
    for i in bpy.context.selected_objects:
        i.rotation_euler.y = bpy.context.active_object.rotation_euler.y

def RotZ(context):
    for i in bpy.context.selected_objects:
        i.rotation_euler.z = bpy.context.active_object.rotation_euler.z
## Aling Scale
def ScaleAll(context):
    for i in bpy.context.selected_objects:
        i.scale = bpy.context.active_object.scale

def ScaleX(context):
    for i in bpy.context.selected_objects:
        i.scale.x = bpy.context.active_object.scale.x

def ScaleY(context):
    for i in bpy.context.selected_objects:
        i.scale.y = bpy.context.active_object.scale.y

def ScaleZ(context):
    for i in bpy.context.selected_objects:
        i.scale.z = bpy.context.active_object.scale.z

## Classes

## Align All Rotation And Location
class AlignOperator(bpy.types.Operator):
    ''''''
    bl_idname = "object.AlignObjects"
    bl_label = "Align Selected To Active"

    @classmethod
    def poll(cls, context):
        return context.active_object != None

    def execute(self, context):
        main(context)
        return {'FINISHED'}

#######################Align Location########################
## Align LocationAll
class AlignLocationOperator(bpy.types.Operator):
    ''''''
    bl_idname = "object.AlignObjectsLocationAll"
    bl_label = "Align Selected Location To Active"

    @classmethod
    def poll(cls, context):
        return context.active_object != None

    def execute(self, context):
        LocAll(context)
        return {'FINISHED'}
## Align LocationX
class AlignLocationXOperator(bpy.types.Operator):
    ''''''
    bl_idname = "object.AlignObjectsLocationX"
    bl_label = "Align Selected Location X To Active"

    @classmethod
    def poll(cls, context):
        return context.active_object != None

    def execute(self, context):
        LocX(context)
        return {'FINISHED'}
## Align LocationY
class AlignLocationYOperator(bpy.types.Operator):
    ''''''
    bl_idname = "object.AlignObjectsLocationY"
    bl_label = "Align Selected Location Y To Active"

    @classmethod
    def poll(cls, context):
        return context.active_object != None

    def execute(self, context):
        LocY(context)
        return {'FINISHED'}
## Align LocationZ
class AlignLocationZOperator(bpy.types.Operator):
    ''''''
    bl_idname = "object.AlignObjectsLocationZ"
    bl_label = "Align Selected Location Z To Active"

    @classmethod
    def poll(cls, context):
        return context.active_object != None

    def execute(self, context):
        LocZ(context)
        return {'FINISHED'}

#######################Align Rotation########################
## Align RotationAll
class AlignRotationOperator(bpy.types.Operator):
    ''''''
    bl_idname = "object.AlignObjectsRotationAll"
    bl_label = "Align Selected Rotation To Active"

    @classmethod
    def poll(cls, context):
        return context.active_object != None

    def execute(self, context):
        RotAll(context)
        return {'FINISHED'}
## Align RotationX
class AlignRotationXOperator(bpy.types.Operator):
    ''''''
    bl_idname = "object.AlignObjectsRotationX"
    bl_label = "Align Selected Rotation X To Active"

    @classmethod
    def poll(cls, context):
        return context.active_object != None

    def execute(self, context):
        RotX(context)
        return {'FINISHED'}
## Align RotationY
class AlignRotationYOperator(bpy.types.Operator):
    ''''''
    bl_idname = "object.AlignObjectsRotationY"
    bl_label = "Align Selected Rotation Y To Active"

    @classmethod
    def poll(cls, context):
        return context.active_object != None

    def execute(self, context):
        RotY(context)
        return {'FINISHED'}
## Align RotationZ
class AlignRotationZOperator(bpy.types.Operator):
    ''''''
    bl_idname = "object.AlignObjectsRotationZ"
    bl_label = "Align Selected Rotation Z To Active"

    @classmethod
    def poll(cls, context):
        return context.active_object != None

    def execute(self, context):
        RotZ(context)
        return {'FINISHED'}
#######################Align Scale########################
## Scale All
class AlignScaleOperator(bpy.types.Operator):
    ''''''
    bl_idname = "object.AlignObjectsScaleAll"
    bl_label = "Align Selected Scale To Active"

    @classmethod
    def poll(cls, context):
        return context.active_object != None

    def execute(self, context):
        ScaleAll(context)
        return {'FINISHED'}
## Align ScaleX
class AlignScaleXOperator(bpy.types.Operator):
    ''''''
    bl_idname = "object.AlignObjectsScaleX"
    bl_label = "Align Selected Scale X To Active"

    @classmethod
    def poll(cls, context):
        return context.active_object != None

    def execute(self, context):
        ScaleX(context)
        return {'FINISHED'}
## Align ScaleY
class AlignScaleYOperator(bpy.types.Operator):
    ''''''
    bl_idname = "object.AlignObjectsScaleY"
    bl_label = "Align Selected Scale Y To Active"

    @classmethod
    def poll(cls, context):
        return context.active_object != None

    def execute(self, context):
        ScaleY(context)
        return {'FINISHED'}
## Align ScaleZ
class AlignScaleZOperator(bpy.types.Operator):
    ''''''
    bl_idname = "object.AlignObjectsScaleZ"
    bl_label = "Align Selected Scale Z To Active"

    @classmethod
    def poll(cls, context):
        return context.active_object != None

    def execute(self, context):
        ScaleZ(context)
        return {'FINISHED'}

## registring
def register():
    pass

def unregister():
    pass

if __name__ == "__main__":
    register()