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

« back to all changes in this revision

Viewing changes to release/scripts/obdatacopier.py

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!BPY
 
2
 
 
3
""" Registration info for Blender menus: <- these words are ignored
 
4
Name: 'Data Copier'
 
5
Blender: 232
 
6
Group: 'Object'
 
7
Tip: 'Copy data from active object to other selected ones.'
 
8
"""
 
9
 
 
10
__author__ = "Jean-Michel Soler (jms)"
 
11
__url__ = ("blender", "elysiun",
 
12
"Script's homepage, http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_lampdatacopier.htm",
 
13
"Communicate problems and errors, http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender")
 
14
__version__ = "0.1.1"
 
15
 
 
16
__bpydoc__ = """\
 
17
Use "Data Copier" to copy attributes from the active object to other selected ones of
 
18
its same type.
 
19
 
 
20
This script is still in an early version but is already useful for copying
 
21
attributes for some types of objects like lamps and cameras.
 
22
 
 
23
Usage:
 
24
 
 
25
Select the objects that will be updated, select the object whose data will
 
26
be copied (they must all be of the same type, of course), then run this script.
 
27
Toggle the buttons representing the attributes to be copied and press "Copy".
 
28
"""
 
29
 
 
30
# ----------------------------------------------------------
 
31
# Object DATA copier 0.1.1
 
32
# (c) 2004 jean-michel soler
 
33
# -----------------------------------------------------------
 
34
#----------------------------------------------
 
35
# Page officielle/official page du blender python Object DATA copier:
 
36
#   http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_lampdatacopier.htm
 
37
# Communiquer les problemes et erreurs sur:
 
38
# To Communicate problems and errors on:
 
39
#   http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender
 
40
#---------------------------------------------
 
41
# Blender Artistic License
 
42
# http://download.blender.org/documentation/html/x21254.html
 
43
#---------------------------------------------
 
44
 
 
45
import Blender
 
46
from Blender import *
 
47
from Blender.Draw import *
 
48
from Blender.BGL import *
 
49
 
 
50
 
 
51
O = Object.GetSelected()
 
52
 
 
53
def renew():
 
54
     global O
 
55
     MAJ='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
 
56
     O = Object.GetSelected()
 
57
     param= [ p for p in dir(O[0].getData()) if (p.find('set')!=0 and p.find('get')!=0 and (MAJ.find(p[0])==-1 or (p in ['R','G','B']))) ]  
 
58
     PARAM={}
 
59
     evt=4
 
60
     doc='doc' 
 
61
     for p in param:
 
62
         try:
 
63
           if p=='mode':
 
64
              try:
 
65
                 exec "doc=str(%s.Modes)+' ; value : %s'"%( O[0].getType(), str(O[0].getData().mode) )
 
66
              except:
 
67
                 exec """doc= '%s'+' value = '+ str(O[0].getData().%s)"""%(p,p) 
 
68
           elif p=='type':
 
69
               try:
 
70
                 exec "doc=str(%s.Types)+' ; value : %s'"%( O[0].getType(), str(O[0].getData().type) )
 
71
               except:
 
72
                 exec """doc= '%s'+' value = '+ str(O[0].getData().%s)"""%(p,p) 
 
73
           else:
 
74
             exec """doc= '%s'+' value = '+ str(O[0].getData().%s)"""%(p,p)
 
75
             if doc.find('built-in')!=-1:
 
76
                exec """doc= 'This is a function ! Doc = '+ str(O[0].getData().%s.__doc__)"""%(p)
 
77
         except:    
 
78
             doc='Doc...' 
 
79
         PARAM[p]=[Create(0),evt,doc]
 
80
         evt+=1
 
81
     return PARAM
 
82
 
 
83
def copy():
 
84
   global PARAM
 
85
   OBJECT=None
 
86
   TYPE=None
 
87
 
 
88
   for O in Blender.Object.GetSelected():
 
89
      if O.getType()!='Mesh' and O.getType()!='Empty' :
 
90
          if OBJECT==None and TYPE==None:
 
91
               OBJECT=O.getData()
 
92
               TYPE= O.getType()
 
93
 
 
94
          elif O.getType()==TYPE:
 
95
            for p in PARAM.keys():
 
96
               if  PARAM[p][0].val==1:
 
97
                  try:
 
98
                    exec "O.getData().%s=OBJECT.%s"%(p,p) 
 
99
                  except:
 
100
                    errormsg = "Type Error|It's not possible to copy %s to %s types." % (p,TYPE)
 
101
                    Blender.Draw.PupMenu(errormsg)
 
102
 
 
103
PARAM= renew()
 
104
 
 
105
def EVENT(evt,val):
 
106
   pass
 
107
 
 
108
def BUTTON(evt):
 
109
   global PARAM   
 
110
   if (evt==1):
 
111
         Exit()
 
112
 
 
113
   if (evt==2):
 
114
 
 
115
         copy()
 
116
         Blender.Redraw()
 
117
 
 
118
   if (evt==3):
 
119
         PARAM= renew()
 
120
         Blender.Redraw()
 
121
 
 
122
def DRAW():
 
123
  global PARAM, O
 
124
  glColor3f(0.7, 0.7, 0.7)
 
125
  glClear(GL_COLOR_BUFFER_BIT)
 
126
  glColor3f(0.1, 0.1, 0.15)    
 
127
 
 
128
  size=Buffer(GL_FLOAT, 4)
 
129
  glGetFloatv(GL_SCISSOR_BOX, size)
 
130
  size= size.list
 
131
  for s in [0,1,2,3]: size[s]=int(size[s])
 
132
  ligne=20
 
133
 
 
134
  Button ("Exit",1,20,4,80,ligne)
 
135
  Button ("Copy",2,102,4,80,ligne)
 
136
  Button ("renew",3,184,4,80,ligne)
 
137
 
 
138
  glRasterPos2f(20, ligne*2-8)
 
139
  Text(O[0].getType()+" DATA copier")
 
140
 
 
141
 
 
142
  max=size[3] / 22 -2
 
143
  pos   = 1
 
144
  decal = 20
 
145
  key=PARAM.keys()
 
146
  key.sort()
 
147
  for p in key:
 
148
     if  pos==max:
 
149
         decal+=102
 
150
         pos=1
 
151
     else:
 
152
         pos+=1       
 
153
     PARAM[p][0]=Toggle(p,
 
154
                      PARAM[p][1],
 
155
                      decal,
 
156
                      pos*22+22,
 
157
                      100,
 
158
                      20, 
 
159
                      PARAM[p][0].val,str(PARAM[p][2]))
 
160
 
 
161
  
 
162
Register(DRAW,EVENT,BUTTON)