Hello All,
First I would like to say a big thanks to the creators of Panda 3D, it has reignited my interest in programming. I am both new to Panda and Python and am amazed at how quickly they produce results. Second to the community for providing all of the code samples and solutions…
My issue:
I create objects in the world dynamicaly and am only able to remove the last created object.
My goal:
I am trying to read a file for new data, upon which, if new data is found draw 3d text and some other objects in the world only to exist for a short period of time and then disappear. Currently if I only create one object it will dissapear fine, but if I create multiple objects before the first disappears, they stay rendered. Any ideas would be of great help. Perhaps I should be doing something with Node instead of NodePath?
The code:
# Read Syslog Files, Check for new data, call DrawConnection Task.
def ReadSyslog(self,task):
if task.frame == 0:
os.remove(r'c:\temp\test.txt') # Delete old data.
f = open(r'c:\temp\test.txt', 'w') # Create empty new syslog file.
f.close()
self.syslogfile = open(r'c:\temp\test.txt', 'r') # Open Syslog file.
self.IP_Line = self.syslogfile.readline() # Continually read single line from file each frame.
if not self.IP_Line: # If no new data, do loop task.
#print 'Nothing New'
return Task.cont
else: # New data detected, launch DrawConnection Task.
taskMgr.add(self.DrawConnection,"DrawConnection")
return Task.cont
# Draw IP Connection pair task, then erase x frames later.
def DrawConnection(self,task):
if task.frame == 0:
self.box = loader.loadModel("models/box")
self.box.reparentTo(render)
self.box.setPos(100,0,100)
self.box.setScale(5)
self.printText("SRCip",self.IP_Line,(1,1,1),3).setPos(150,0,150) # Draw SRC IP.
print 'Create Object: ', self.IP_Line, self.box.ls(), self.text3d.ls()
taskMgr.add(self.RemoveConnection,'RemoveConnection')
if task.frame == 300:
taskMgr.remove('DrawConnection')
return Task.cont
def RemoveConnection(self,task):
if task.frame == 300:
print 'Remove Object: ', task.frame, task.time, self.box.ls()
self.box.removeNode()
self.text3d.removeNode()
return Task.cont
[/code]
Sorry for the overrun code lines.