When you use MDagModifier to delete the last shape under a transform, the transform is automatically deleted as well. That is the normal Maya behavior. It helps to keep the scene clear of orphaned transforms and is consistent with MDagModifier::createNode(), which will automatically create a parent if none is specified when creating the node.
However, you need to know that MDagModifier::reparentNode() would not delete empty parents when that happens. And the 'delete' command doesn't behave the same way since it uses the internal equivalent of MDGModifier to delete the node, which leaves the parent intact.

Said that if you want to protect a node from being deleted automatically by Maya when such situation occurs you can do so by using the MPxNode::setExistWithoutInConnections() and MPxNode::setExistWithoutOutConnections() methods which will tell Maya to not delete your node if you lose all your upstream and/or downstream connections.

Leave a Reply