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

object_sel2dupgroup.py « scripts « release - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1b8067e07fb8248d473c996ab469ad1319e5f26a (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
#!BPY

"""
Name: 'Selection to DupliGroup'
Blender: 243
Group: 'Object'
Tooltip: 'Turn the selection into a dupliGroup using the active objects transformation, objects are moved into a new scene'
"""

__bpydoc__=\
'''
'''

# ***** BEGIN GPL LICENSE BLOCK *****
#
# Script copyright (C) Campbell Barton
#
# 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# ***** END GPL LICENCE BLOCK *****
# --------------------------------------------------------------------------


from Blender import *

def main():
	scn = Scene.GetCurrent()
	ob_act = scn.objects.active
	
	if not ob_act:
		Draw.PupMenu('Error%t|No active object')
	
	dup_name = ob_act.name
	
	obsel = list(scn.objects.context)
	
	# Sanity check
	for ob in obsel:
		parent = ob.parent
		if parent:
			if not parent.sel or parent not in obsel:
				Draw.PupMenu('Error%t|Objects "'+ob.name+'" parent "'+parent.name+'" is not in the selection')
				return
	
	mat_act = ob_act.matrixWorld
	
	# new group
	grp = Group.New(dup_name)
	grp.objects = obsel
	
	# Create the new empty object to be the dupli
	ob_dup = scn.objects.new('Empty')
	ob_dup.setMatrix(mat_act)
	ob_dup.name = dup_name + '_dup'
	
	ob_dup.enableDupGroup = True
	ob_dup.DupGroup = grp
	
	scn_new = Scene.New(dup_name)
	
	# Transform the objects to remove the active objects matrix.
	mat_act_inv = mat_act.copy().invert()
	for ob in obsel:
		if not ob.parent:
			ob.setMatrix(ob.matrixWorld * mat_act_inv)
		
		scn_new.objects.link(ob)
		scn.objects.unlink(ob)	


if __name__ == '__main__':
	main()