WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 07-21-2007, 10:54 PM
k_iwan k_iwan is offline
Member
 
Join Date: May 2006
Posts: 115
Unhappy <node3d>.remove() ... help how does this work?

Hi I'm having trouble of deleting object, here is my code;

Quote:
###
class Parent:
def __init__(self):
print "init from parent"

def duit(self,duit):
self.salary = self.salary + duit
return self.salary

def remove(self):
self.obj.remove()

class Child(Parent):
def __init__(self):
Parent.__init__(self)
print "init from child"

self.obj = viz.add('duck.cfg')
self.salary = 100

class World:
def __init__(self):
self.c = Child()
self.final = self.c.duit(50000)
print self.final

w=World()
viz.go()
###
When I do 'w.c.remove()', the 3d model is gone, but w.c still exists.
If I do 'del w.c', it will delete w.c, then I can no longer delete the duck.

Does that mean that in my World class, I need to create method to delete the object first and the reference/instance later? e.g when the child (duck) collide with ball and delete child within the World class, I need to do.... self.c.remove() and del self.c later?

I thought that <node3d>.remove would delete object from the scene including associated instances ? Is there a way to delete instance along with the object as well?

Thank you for your time. (all the tabs in my code seem to be missing when I copy-paste here)

Kind Regards,
Iwan
Reply With Quote
  #2  
Old 07-23-2007, 11:55 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

Please use the [code][/code] tags when posting code. It will preserve your tabs.

The <node>.remove() command will delete the object from the Vizard engine, however the Python object will still exist. If you want to remove the node from Vizard and remove the reference to it, then you can create a wrapper function that does it for you. However, if some other code is referencing the object, then that reference will continue to exist. Example:
Code:
class Parent:
	def __init__(self):
		print "init from parent"

	def duit(self,duit):
		self.salary = self.salary + duit
		return self.salary

	def remove(self):
		self.obj.remove()

class Child(Parent):
	def __init__(self):
		Parent.__init__(self)
		print "init from child"

		self.obj = viz.add('duck.cfg')
		self.salary = 100

class World:
	def __init__(self):
		self.c = Child()
		self.final = self.c.duit(50000)
		print self.final

	def remove(self):
		self.c.remove()
		del self.c

w=World()
viz.go()


#Print value of w.c
print w.c

#Save referenc to w.c
c_ref = w.c

#Remove child
w.remove()

#Try printing value of w.c
try:
	print w.c
except AttributeError:
	print 'w.c does not exist'

#Reference to child still exists
print c_ref
Reply With Quote
  #3  
Old 07-23-2007, 04:53 PM
k_iwan k_iwan is offline
Member
 
Join Date: May 2006
Posts: 115
Talking

Hi farshizzo,

Thank you for your explanation about deleting object in vizard, I really appreciate that

I will use the appropriate tags next time posting codes.

Kind Regards,
Iwan
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:57 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC