After all those traversing and editing, it is very easy to delete nodes. Simply make a list of nodes or a single node, and pass it to the appropriate method of the scene object. The script below deletes all the selected nodes:

scene.del(scene.selection);

Another script, deletes a first top level node in the scene:

scene.del(scene.root.children[0]);

You can’t delete the root node, so you’ll get an error if you try the following code:

scene.del(scene.root);

That’s all you need to know about the deletion.