How to remove from screen specific elements created with a tag

I need to remove from 3D space certain itens that I added.

So I decided to investigate and found a NodePathCollection using this code.

print(self.app.render.getChildren())

Which gives me the following output:

render/UCS
render/xText
render/yText
render/zText
render/Grid
render/DrawingPlane
render/UCS mouse
render/camera_target
render/DXF
render/DXF
render/DXF
render/DXF

I want to remove only ‘render/DXF’ objects, since they are no longer useful. How can I achieve this?

Solved with:

,

    def clear_dxf(self):
        for children in self.app.render.getChildren():
            if children.getName() == 'DXF':
                children.removeNode()

As an alternative approach, I think that you can get a collection containing only the relevant nodes via the “findAllMatches” method of NodePath.

Something like this:

def clear_dxf(self):
    npCollection = self.app.render.findAllMatches("**/DXF")
    for np in npCollection:
        np.removeNode()

See here for more information on searching in this way:
https://docs.panda3d.org/1.10/python/programming/scene-graph/searching-scene-graph