Only last NodePath removed

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.
            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.
            return Task.cont

   # Draw IP Connection pair task, then erase x frames later.
    def DrawConnection(self,task):

        if task.frame == 0:
   = loader.loadModel("models/box")
            self.printText("SRCip",self.IP_Line,(1,1,1),3).setPos(150,0,150)    # Draw SRC IP.
            print 'Create Object: ', self.IP_Line,,
        if task.frame == 300:
        return Task.cont

    def RemoveConnection(self,task):
        if task.frame == 300:
            print 'Remove Object: ', task.frame, task.time,
        return Task.cont


Sorry for the overrun code lines. = loader.loadModel("models/box")

Just a guess, but if you already have a at the time you make this call, you will overwrite that pointer with a new value for, and now you no longer have a handle to the old, so you can no longer delete it.

Instead of doing this, you can either (a) delete the old before you assign a new value to it, so you never have more than one; or (b) if you want to have more than one but also keep track of it, then you will need to append all of them to a list, and then iterate through the list when you’re ready to delete them.

Or, you can attach them all to the same parent node, and then just remove that parent node.


Wow, that was a fast reply :slight_smile:

Yes, I need each object to exist for a period of time and there will be many in various locations appearing and disappearing at different times. So the list idea sounds good, I did try something like that but was not sure that was the right way, will revisit it now and see if that will do the trick. Thanks for the feedback!

Update: The list trick worked. You rock! Thanks again, now I can spend some time with the rest of the family :0