~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to release/scripts/object_sel2dupgroup.py

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!BPY
 
2
 
 
3
"""
 
4
Name: 'Selection to DupliGroup'
 
5
Blender: 243
 
6
Group: 'Object'
 
7
Tooltip: 'Turn the selection into a dupliGroup using the active objects transformation, objects are moved into a new scene'
 
8
"""
 
9
 
 
10
__bpydoc__=\
 
11
'''
 
12
'''
 
13
 
 
14
# ***** BEGIN GPL LICENSE BLOCK *****
 
15
#
 
16
# Script copyright (C) Campbell Barton
 
17
#
 
18
# This program is free software; you can redistribute it and/or
 
19
# modify it under the terms of the GNU General Public License
 
20
# as published by the Free Software Foundation; either version 2
 
21
# of the License, or (at your option) any later version.
 
22
#
 
23
# This program is distributed in the hope that it will be useful,
 
24
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
25
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
26
# GNU General Public License for more details.
 
27
#
 
28
# You should have received a copy of the GNU General Public License
 
29
# along with this program; if not, write to the Free Software Foundation,
 
30
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
31
#
 
32
# ***** END GPL LICENCE BLOCK *****
 
33
# --------------------------------------------------------------------------
 
34
 
 
35
 
 
36
from Blender import *
 
37
 
 
38
def main():
 
39
        scn = Scene.GetCurrent()
 
40
        ob_act = scn.objects.active
 
41
        
 
42
        if not ob_act:
 
43
                Draw.PupMenu('Error%t|No active object')
 
44
        
 
45
        dup_name = ob_act.name
 
46
        
 
47
        obsel = list(scn.objects.context)
 
48
        
 
49
        # Sanity check
 
50
        for ob in obsel:
 
51
                parent = ob.parent
 
52
                if parent:
 
53
                        if not parent.sel or parent not in obsel:
 
54
                                Draw.PupMenu('Error%t|Objects "'+ob.name+'" parent "'+parent.name+'" is not in the selection')
 
55
                                return
 
56
        
 
57
        mat_act = ob_act.matrixWorld
 
58
        
 
59
        # new group
 
60
        grp = Group.New(dup_name)
 
61
        grp.objects = obsel
 
62
        
 
63
        # Create the new empty object to be the dupli
 
64
        ob_dup = scn.objects.new('Empty')
 
65
        ob_dup.setMatrix(mat_act)
 
66
        ob_dup.name = dup_name + '_dup'
 
67
        
 
68
        ob_dup.enableDupGroup = True
 
69
        ob_dup.DupGroup = grp
 
70
        
 
71
        scn_new = Scene.New(dup_name)
 
72
        
 
73
        # Transform the objects to remove the active objects matrix.
 
74
        mat_act_inv = mat_act.copy().invert()
 
75
        for ob in obsel:
 
76
                if not ob.parent:
 
77
                        ob.setMatrix(ob.matrixWorld * mat_act_inv)
 
78
                
 
79
                scn_new.objects.link(ob)
 
80
                scn.objects.unlink(ob)  
 
81
 
 
82
 
 
83
if __name__ == '__main__':
 
84
        main()