Move child nodes

Hi,

Is it possible to remove all child nodes of my first node, replacing them all with the child nodes of my second node?
I’ve tried this:

self.removeNode()
other.copyTo(self)

But removeNode marks my node as invalid, and thus copyTo spews out an AssertionError. Also, I don’t know whether this makes sure my main nodepath’s properties stay like they were.

Thanks in advance,
pro-rsoft

Um, not entirely sure what you’re asking for.

First, you should know that self.removeNode() will detach a node from a scene graph and then declare that NodePath invalid. But self.detachNode() will do the same thing, except that it doesn’t declare the NodePath invalid. So you could have just used detachNode() instead of removeNode().

But that doesn’t sound like what you were asking for. That would just end up with your node an orphan, and with an additional child of your node. Maybe you meant to do something like this:

self.getChildren().detach()
other.getChildren().reparentTo(self)

But that takes the children away from other. If you want to copy them instead, you could do this:

self.getChildren().detach()
for node in other.getChildren().asList():
  node.copyTo(self)

Or this:

self.getChildren().detach()
other.copyTo(NodePath()).getChildren().reparentTo(self)

David

I guess you have been exposed too long to C++, welcome back to Python !
To remove children, there is NodePath.removeChildren, it’s an extension in libpandaModules.py.
Or use PandaNode’s :

and there is also :

Ah, thanks a lot! I was only lookin’ at NodePath functions and not at PandaNode functions. I’ve also found copy_children there which was also really useful!
It’s actually for PGMM (in C++), but I was experimenting a bit with it first on the python shell. :wink: