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

    Creating object in CommandData does not update Object Manager

    Cinema 4D SDK
    c++
    2
    2
    488
    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.
    • CJtheTigerC
      CJtheTiger
      last edited by CJtheTiger

      I'm on 2023.2.2 in C++.

      My CommandData plugin creates a cube and inserts it into the document yet the object manager does not show the cube until I select it in the viewport.

      Code:

      Bool MyCommand::Execute(BaseDocument* doc, GeDialog* parentManager)
      {
          auto cube = BaseObject::Alloc(Ocube);
          doc->InsertObject(cube, nullptr, nullptr, false);
          EventAdd();
      
          return true;
      }
      

      I was hoping the call to EventAdd would fix that but it doesn't.

      2f99c27d-370f-41e6-b8b2-8c3262635047-Cinema_4D_4a6urI6jaQ.gif

      What does work however is making the cube the active object after inserting it.

      Bool MyCommand::Execute(BaseDocument* doc, GeDialog* parentManager)
      {
          auto cube = BaseObject::Alloc(Ocube);
          doc->InsertObject(cube, nullptr, nullptr, false);
          doc->SetActiveObject(cube);
      
          return true;
      }
      

      Note how apparently I don't even need to call EventAdd anymore.

      fd0ba8b8-fb13-484f-8dfd-6b0bcd3b468c-Cinema_4D_WErbfmttGk.gif

      Then again if I want to support undo I do need EventAdd again or the object manager won't update anymore.

      Bool MyCommand::Execute(BaseDocument* doc, GeDialog* parentManager)
      {
          auto cube = BaseObject::Alloc(Ocube);
          doc->StartUndo();
          doc->InsertObject(cube, nullptr, nullptr, false);
          doc->AddUndo(UNDOTYPE::NEWOBJ, cube);
          doc->EndUndo();
      
          doc->SetActiveObject(cube);
          EventAdd();
      
          return true;
      }
      

      My question is: Why does the first code not update the object manager?

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

        Hi sadly this is a known issue, see EventAdd is not working.

        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

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