How does InsertObject work [SOLVED]



  • On 17/07/2015 at 16:03, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   16 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    Hello,

    I'm getting crazy. I want to cut an object and insert it as an child to an null object. Here's my code:

    BaseObject* op = doc->GetFirstObject();  
    BaseObject* wallsNull = BaseObject::Alloc(Onull);  
    wallsNull->SetName("UE4Ex_Walls");  
    doc->InsertObject(wallsNull,nullptr,nullptr);  
    doc->InsertObject(op,wallsNull,nullptr);
    

    After executing this, my whole objects of the scene are inside the "wallsNull" and not only the first one. Also cinema freezes.
    What I'm doing wrong?

    Edit: Cinema doesn't freeze but I can't close it.

    Thanks



  • On 17/07/2015 at 16:20, xxxxxxxx wrote:

    You can only insert a new object once into the document.  If you want it to be at the root, use the first doc->ObjectInsert() call.  The second call is gibberish. You cannot insert op underneath the object your are inserting.  If you want that then you have to remove op and insert under it:

    doc->InsertObject(wallsNull, nullprt, nullptr);
    op->Remove();
    doc->InsertObject(op, wallsNull, nullptr);
    

    So, removing op frees it from the document's hierarchical chain so that you can then reinsert it into the document where you want in that hierarchy.  Understand?



  • On 17/07/2015 at 16:30, xxxxxxxx wrote:

    Thank you so much!!! I understand and it works now :)


Log in to reply