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

    Free all BaseObject

    Cinema 4D SDK
    c++
    3
    3
    798
    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.
    • Z
      zhhm156
      last edited by a_block

      I have a question about clean all baseobjects within document.There were many Baseobjects using Baseobject::Alloc() to achieve and put into Basedocument. If I use Basedocument::Free() to clean all info,Is it necessarily that all objects were destoryed using baseobject::Free() within doc one by one?

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

        Hello there,

        if you want to completely empty an document, simply call Flush(), it empties and destroys everything in it. BaseDocument.Flush()
        This also deletes everything, not only BaseObjects.

        However, you stated that you only want to Free all BaseObjects, you then have to iterate over the entire document and remove them manually.

        Could look like this then:

        inline void g_DeleteAllObjects(BaseDocument* doc)
        {
        	if (!doc)
        		return;
        
        	auto obj = doc->GetFirstObject();
        
        	while (obj)
        	{
        		const auto tempObj = obj->GetNext();
        		obj->Remove();
        		BaseObject::Free(obj);
        		obj = tempObj;
        	}
        }
        
        
        1 Reply Last reply Reply Quote 1
        • a_blockA
          a_block
          last edited by

          Hi,

          what @mp5gosu is showing in his code snippet is actually a quite common concept in Cinema 4D. More on this topic can also be found in the GeListNode manual in our C++ documentation.

          One request from my side: Please do not use all capital letters in the subject of a topic. Our forum tries to emphasize threads which are unread by a user by temporarily formatting a subject in all capital letters. So if you do as you did here ("FREE ALL BASEOBJECT") the thread always looks like it is still unread. I changed it here in this thread.

          And as a small reminder, please make use of our tagging system in this forum to provide a bit of additional information for a thread and to help us keep this forum nice and tidy and easily searchable. See Read Before Posting..

          Lastly I turned your thread into a question (see How to Post Questions). Another feature we'd like to see people making use of in order to increase the usefulness of this forum.

          Cheers,
          Andreas

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