Move an object in hierarchy
-
Hi everyone,
In the script I'm writing I need to delete an object with some children, without deleting the children. So, I have to "move" the children one step up of the hierarchy, before deleting the parent. I went through the documentation but haven't found any method to do that (to move an object in its hierarchy). Any suggestion?
-
Hi, you have to write an own routine for that. I was writing this one a while ago:
/** * @brief Moves all children of srcObj to tgtObj. Adds Undos. * @param srcObj The source object * @param tgtObj The target object */ inline void g_MoveChildren(BaseObject* srcObj, BaseObject* tgtObj) { if (!srcObj) return; auto doc = srcObj->GetDocument(); if (!doc) return; auto child = srcObj->GetDown(); while (child) { const auto temp = child->GetNext(); doc->AddUndo(UNDOTYPE::CHANGE, child); child->Remove(); child->InsertUnderLast(tgtObj); child = temp; } }
For further information about hierarchy manipulation, see https://developers.maxon.net/docs/cpp/2023_2/page_manual_gelistnode.html#page_manual_gelistnode_lists_edit
-
Hi Rage,
you could try CallCommand() with id 1019951 - calling this should delete all selected objects without deleting their children. Might also do what you're after?
WP.
-
Hi,
both answers already provide valid solutions. Nice.
@Rage: Please also consider to use the tagging system (see Read Before Posting) and the Question and Answer feature (see Q&A New Functionality). Especially the tags can help, like for example in this case @mp5gosu would probably have provided you with Python code, if the respective tag was set.
Besides setting tags and changing into a question, I have also moved this thread into the Cinema 4D Development category.And then I want to add a few links to Python docs:
GeListNode
CallCommand()Cheers,
Andreas