|
From: Rob S. <sa...@ph...> - 2003-09-28 20:56:09
|
My previous copyobjects() choked on curves [and labels].
Here's an improved version which works with curves.
See below for a possible bug with the label object.
def copyobjects(scene1,scene2):
# based on http://www.vpython.org/webdoc/visual/options.html
# Copy all Visual objects from scene1 into scene2
scene2.select()
scenelist=scene1.objects
###
### reverse() is needed so that the items in the destination list
### of objects are in correspondence those of the source list
scenelist.reverse()
for obj in scenelist:
newobj = obj.__class__() # create object in scene2
if obj.__class__== 'curve': ###
for i in obj.pos: ###
newobj.append(pos=i) ###
for member in obj.__members__:
if member == 'display': continue # avoid putting into scene1
setattr(newobj,member,getattr(obj,member))
This function now seems to work for all of the "Basic Display Objects"
_except_ for the label object.
BUG?
It appears that the label fails to return the __members__
attribute. Browsing the source code, it seems that:
in label.cpp,
Object Label::getattr(const char* _attr) is missing the case
if (attr == "__members__") ....
as one finds in prim.cpp and arrprim.cpp.
Here's an example (which fails):
from visual import *
earth=sphere()
print earth.__class__
print dir(earth)
print earth.__dict__
print earth.__methods__
print earth.__members__
print "==================="
earthlabel = label(text='Our Earth')
print earthlabel.__class__
print dir(earthlabel)
print earthlabel.__dict__
print earthlabel.__methods__
print earthlabel.__members__
Rob Salgado
|