Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Move an object in hierarchy

    Cinema 4D SDK
    python
    4
    4
    1.8k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      Rage
      last edited by a_block

      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?

      1 Reply Last reply Reply Quote 0
      • M
        mp5gosu
        last edited by mp5gosu

        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

        1 Reply Last reply Reply Quote 4
        • WickedPW
          WickedP
          last edited by WickedP

          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.

          wickedp.com

          1 Reply Last reply Reply Quote 2
          • a_blockA
            a_block
            last edited by

            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

            1 Reply Last reply Reply Quote 1
            • First post
              Last post