This repository has been archived by the owner on Jul 23, 2019. It is now read-only.
forked from knekke/blender_addons
-
Notifications
You must be signed in to change notification settings - Fork 1
/
B28_match_transforms.py
85 lines (67 loc) · 2.38 KB
/
B28_match_transforms.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
bl_info = {
"name": "Match Transforms",
"author": "knekke",
"version": (1, 0),
"blender": (2, 80, 0),
"location": "Tools/Transform Panel",
"description": "Matches the transforms of selected objects to the active object",
"warning": "",
"wiki_url": "",
"category": "Object",
}
import bpy
class MatchTransformsOperator(bpy.types.Operator):
"Match Transforms - selected to active Objects"
bl_idname = "object.match_transform"
bl_label = "Match Transform"
location = bpy.props.BoolProperty()
rotation = bpy.props.BoolProperty()
scale = bpy.props.BoolProperty()
def execute(self, context):
target = bpy.context.object
loc = target.matrix_world.to_translation()
rot = target.matrix_world.to_euler('XYZ')
scl = target.matrix_world.to_scale()
for i in bpy.context.selected_objects:
if not i == target:
if self.location:
i.location = loc
if self.rotation:
i.rotation_euler = rot
if self.scale:
i.scale = scl
#target.select_set(state=False)
#bpy.context.view_layer.objects.active = target #bpy.context.selected_objects[-1]
return {'FINISHED'}
def add_button(self, context):
layout = self.layout
col = layout.column()
col.label(text="Match selected to active")
row = col.row(align=True)
row.alignment = 'EXPAND'
row2 = col.row(align=True)
row2.alignment = 'EXPAND'
butt = layout.operator("object.match_transform", text="All", text_ctxt="All")
butt.location = True
butt.rotation = True
butt.scale = True
buttl = layout.operator("object.match_transform", text="Loc")
buttl.location = True
buttl.rotation = False
buttl.scale = False
buttr = layout.operator("object.match_transform", text="Rot")
buttr.location = False
buttr.rotation = True
buttr.scale = False
butts = layout.operator("object.match_transform", text="Scl")
butts.location = False
butts.rotation = False
butts.scale = True
def register():
bpy.utils.register_class(MatchTransformsOperator)
bpy.types.VIEW3D_PT_tools_active.append(add_button)
def unregister():
bpy.utils.unregister_class(MatchTransformsOperator)
bpy.types.VIEW3D_PT_tools_active.remove(add_button)
if __name__ == "__main__":
register()