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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2006-07-09 18:22:21 +0400
committerCampbell Barton <ideasman42@gmail.com>2006-07-09 18:22:21 +0400
commit158d430ca9668e19b8b57a62cae7f3e855e152dd (patch)
tree4de3c4b196687218b48d1732ee5a76355ab79378 /release/scripts/obdatacopier.py
parent289259c09c6c8cb631765ec18591458412ad07d5 (diff)
updated mesh boneweight copy not to error with no selection.]
updated obdatacopier to support mesh objects and added a more general way of choosing data to show or ignore in the button list.
Diffstat (limited to 'release/scripts/obdatacopier.py')
-rw-r--r--release/scripts/obdatacopier.py249
1 files changed, 151 insertions, 98 deletions
diff --git a/release/scripts/obdatacopier.py b/release/scripts/obdatacopier.py
index 13b5e7a1bb0..3dfdcf68daa 100644
--- a/release/scripts/obdatacopier.py
+++ b/release/scripts/obdatacopier.py
@@ -7,11 +7,11 @@ Group: 'Object'
Tip: 'Copy data from active object to other selected ones.'
"""
-__author__ = "Jean-Michel Soler (jms)"
+__author__ = "Jean-Michel Soler (jms), Campbell Barton (Ideasman42)"
__url__ = ("blender", "elysiun",
"Script's homepage, http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_lampdatacopier.htm",
"Communicate problems and errors, http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender")
-__version__ = "0.1.1"
+__version__ = "0.1.2"
__bpydoc__ = """\
Use "Data Copier" to copy attributes from the active object to other selected ones of
@@ -28,7 +28,7 @@ Toggle the buttons representing the attributes to be copied and press "Copy".
"""
# ----------------------------------------------------------
-# Object DATA copier 0.1.1
+# Object DATA copier 0.1.2
# (c) 2004 jean-michel soler
# -----------------------------------------------------------
#----------------------------------------------
@@ -48,115 +48,168 @@ from Blender.Draw import *
from Blender.BGL import *
-O = Object.GetSelected()
+
+obsel = Object.GetSelected()
+
+type_func_method= type(dir)
+type_func= type(lambda:i)
+type_dict= type({})
+# type_list= type([])
+
def renew():
- global O
- MAJ='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- O = Object.GetSelected()
- 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']))) ]
- PARAM={}
- evt=4
- doc='doc'
- for p in param:
- try:
- if p=='mode':
- try:
- exec "doc=str(%s.Modes)+' ; value : %s'"%( O[0].getType(), str(O[0].getData().mode) )
- except:
- exec """doc= '%s'+' value = '+ str(O[0].getData().%s)"""%(p,p)
- elif p=='type':
- try:
- exec "doc=str(%s.Types)+' ; value : %s'"%( O[0].getType(), str(O[0].getData().type) )
- except:
- exec """doc= '%s'+' value = '+ str(O[0].getData().%s)"""%(p,p)
- else:
- exec """doc= '%s'+' value = '+ str(O[0].getData().%s)"""%(p,p)
- if doc.find('built-in')!=-1:
- exec """doc= 'This is a function ! Doc = '+ str(O[0].getData().%s.__doc__)"""%(p)
- except:
- doc='Doc...'
- PARAM[p]=[Create(0),evt,doc]
- evt+=1
- return PARAM
+ global obsel
+ scn= Blender.Scene.GetCurrent()
+ act_ob= scn.getActiveObject()
+ if act_ob==None:
+ return {}
+
+ act_ob_type= act_ob.getType()
+ act_ob_data= act_ob.getData(mesh=1)
+
+ obsel = Object.GetSelected()
+
+ if act_ob_data==None: # Surf
+ return {}
+
+ PARAM={}
+ evt=4
+ doc='doc'
+
+ for prop_name in dir(act_ob_data):
+ if not prop_name.startswith('__'):
+ # Get the type
+ try: exec 'prop_type= type(act_ob_data.%s)' % prop_name
+ except: prop_type= None
+
+ if prop_type != None and prop_type not in (type_func_method, type_func, type_dict):
+
+ # Now we know that the attribute can be listed in the UI Create a button and tooltip.
+
+ # Tooltip
+ try:
+ if prop_name=='mode':
+ try:
+ exec "doc=str(%s.Modes)+' ; value : %s'"%( act_ob_type, str(act_ob_data.mode) )
+ except:
+ exec """doc= '%s'+' value = '+ str(act_ob.getData(mesh=1).%s)"""%(prop_name, prop_name)
+ elif prop_name=='type':
+ try:
+ exec "doc=str(%s.Types)+' ; value : %s'"%( act_ob_type, str(act_ob_data.type) )
+ except:
+ exec """doc= '%s'+' value = '+ str(act_ob.getData(mesh=1).%s)"""%(prop_name, prop_name)
+ else:
+ exec """doc= '%s'+' value = '+ str(act_ob_data.%s)"""%(prop_name, prop_name)
+ if doc.find('built-in')!=-1:
+ exec """doc= 'This is a function ! Doc = '+ str(act_ob_data.%s.__doc__)"""% prop_name
+ except:
+ doc='Doc...'
+
+ # Button
+ PARAM[prop_name]= [Create(0), evt, doc]
+ evt+=1
+
+ return PARAM
def copy():
- global PARAM
- OBJECT=None
- TYPE=None
-
- for O in Blender.Object.GetSelected():
- if O.getType()!='Mesh' and O.getType()!='Empty' :
- if OBJECT==None and TYPE==None:
- OBJECT=O.getData()
- TYPE= O.getType()
-
- elif O.getType()==TYPE:
- for p in PARAM.keys():
- if PARAM[p][0].val==1:
- try:
- exec "O.getData().%s=OBJECT.%s"%(p,p)
- except:
- errormsg = "Type Error|It's not possible to copy %s to %s types." % (p,TYPE)
- Blender.Draw.PupMenu(errormsg)
-
+ global PARAM
+
+ scn= Blender.Scene.GetCurrent()
+ act_ob= scn.getActiveObject()
+ if act_ob==None:
+ Blender.Draw.PupMenu('Error|No Active Object.')
+ return
+
+ act_ob_type= act_ob.getType()
+
+ if act_ob_type in ('Empty', 'Surf'):
+ Blender.Draw.PupMenu('Error|Copying Empty or Surf object data isnt supported.')
+ return
+
+ act_ob_data= act_ob.getData(mesh=1)
+
+ print '\n\nStarting copy for object "%s"' % act_ob.name
+ some_errors= False
+ for ob in Blender.Object.GetSelected():
+ if ob != act_ob and ob.getType() == act_ob_type:
+ ob_data= None
+ for prop_name, value in PARAM.iteritems():
+ if value[0].val==1:
+
+ # Init the object data if we havnt alredy
+ if ob_data==None:
+ ob_data= ob.getData(mesh=1)
+
+ try:
+ exec "ob_data.%s = act_ob_data.%s"%(prop_name, prop_name)
+ except:
+ some_errors= True
+ print 'Cant copy property "%s" for type "%s"' % (prop_name, act_ob_type)
+ if some_errors:
+ Blender.Draw.PupMenu('Some attributes could not be copied, see console for details.')
+
PARAM= renew()
def EVENT(evt,val):
pass
def BUTTON(evt):
- global PARAM
- if (evt==1):
- Exit()
-
- if (evt==2):
+ global PARAM
+ if (evt==1):
+ Exit()
- copy()
- Blender.Redraw()
+ if (evt==2):
+ copy()
+ Blender.Redraw()
- if (evt==3):
- PARAM= renew()
- Blender.Redraw()
+ if (evt==3):
+ PARAM= renew()
+ Blender.Redraw()
def DRAW():
- global PARAM, O
- glColor3f(0.7, 0.7, 0.7)
- glClear(GL_COLOR_BUFFER_BIT)
- glColor3f(0.1, 0.1, 0.15)
-
- size=Buffer(GL_FLOAT, 4)
- glGetFloatv(GL_SCISSOR_BOX, size)
- size= size.list
- for s in [0,1,2,3]: size[s]=int(size[s])
- ligne=20
-
- Button ("Exit",1,20,4,80,ligne)
- Button ("Copy",2,102,4,80,ligne)
- Button ("renew",3,184,4,80,ligne)
-
- glRasterPos2f(20, ligne*2-8)
- Text(O[0].getType()+" DATA copier")
-
-
- max=size[3] / 22 -2
- pos = 1
- decal = 20
- key=PARAM.keys()
- key.sort()
- for p in key:
- if pos==max:
- decal+=102
- pos=1
- else:
- pos+=1
- PARAM[p][0]=Toggle(p,
- PARAM[p][1],
- decal,
- pos*22+22,
- 100,
- 20,
- PARAM[p][0].val,str(PARAM[p][2]))
+ global PARAM
+
+ scn= Blender.Scene.GetCurrent()
+ act_ob= scn.getActiveObject()
+
+ glColor3f(0.7, 0.7, 0.7)
+ glClear(GL_COLOR_BUFFER_BIT)
+ glColor3f(0.1, 0.1, 0.15)
+
+ size=Buffer(GL_FLOAT, 4)
+ glGetFloatv(GL_SCISSOR_BOX, size)
+ size= size.list
+ for s in [0,1,2,3]: size[s]=int(size[s])
+ ligne=20
+
+ Button("Exit",1,20,4,80,ligne)
+ Button("Copy",2,102,4,80,ligne)
+ Button("Renew",3,184,4,80,ligne)
+
+ glRasterPos2f(20, ligne*2-8)
+ Text(act_ob.getType()+" DATA copier")
+
+
+ max=size[3] / 22 -2
+ pos = 0
+ decal = 20
+ key=PARAM.keys()
+ key.sort()
+ for p in key:
+ if pos==max:
+ decal+=102
+ pos=1
+ else:
+ pos+=1
+
+ PARAM[p][0]=Toggle(p,
+ PARAM[p][1],
+ decal,
+ pos*22+22,
+ 100,
+ 20,
+ PARAM[p][0].val,
+ str(PARAM[p][2]))
Register(DRAW,EVENT,BUTTON)