![]() |
|
|
|
#1
|
|||
|
|||
|
Sorry, forgot to include that class as well.
Here is a super class of GreenObject called Model3D which derives from viz.VizNode Code:
class Model3D(viz.VizNode): GORM = None def __init__(self, string): #Typical string entry if type(string) == str: base = viz.add(string) viz.VizNode.__init__(self, base.id) #Use for on-the-fly creation in Vizard elif isinstance(string, viz.VizNode): base = string viz.VizNode.__init__(self, base.id) elif isinstance(string, int): #We are dealing with a copy that has passed in an id number viz.VizNode.__init__(self, string) else: print 'Copy type', string, type(string) |
|
#2
|
|||
|
|||
|
The node.copy command will pass all extra keyword arguments to the class __init__ method. You can override the copy method in your class and have it pass all the required arguments as keyword arguments to the underlying node.copy method. Example:
Code:
import viz
viz.go()
class MyNode(viz.VizNode):
def __init__(self, model, parameter):
if isinstance(model,basestring):
base = viz.add(model)
viz.VizNode.__init__(self, base.id)
elif isinstance(model, viz.VizNode):
viz.VizNode.__init__(self, model.id)
elif isinstance(model, int):
viz.VizNode.__init__(self, model)
self._parameter = parameter
def copy(self, parameter):
return viz.VizNode.copy(self,parameter=parameter)
node = MyNode('gallery.osgb',0)
nodeCopy = node.copy(1)
|
|
#3
|
|||
|
|||
|
I believe it will work.
I'll create a new instance of the class in the copy constructor and pass the copy into the initializer. This way the copy command will now not just copy viz.VizNode but I can code it to also copy the rest of the parameters I've attached to my new class as well. Thank you, George |
![]() |
| Tags |
| inheritance, viznode |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|