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

    Modeling Kernel Error : Invalid Object

    General Talk
    2
    2
    452
    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.
    • Danchyg1337D
      Danchyg1337
      last edited by Danchyg1337

      Hello!
      I'm trying to change a vertex (point) of a cube and instead getting this error: "Modeling Kernel Error:Invalid Object".
      Here is code. I'm using R20 version.

      BaseObject* const cube = BaseObject::Alloc(Ocube);
      cube->SetName("Default"_s);
      
      doc->StartUndo();
      doc->InsertObject(cube, nullptr, nullptr);
      doc->AddUndo(UNDOTYPE::NEWOBJ, cube);
      doc->EndUndo();
      
      ModelingCommandData mcd;
      BaseContainer bc;
      mcd.doc = doc;
      mcd.op = cube;
      mcd.mode = MODELINGCOMMANDMODE::ALL;
      mcd.flags = MODELINGCOMMANDFLAGS::CREATEUNDO;
      mcd.bc = &bc;
      
      if (!SendModelingCommand(MCOMMAND_MAKEEDITABLE, mcd)) ApplicationOutput("Couldn't make object editable.");
      PolygonObject* pol = static_cast<PolygonObject*>(mcd.result->GetIndex(0));
      
      if (pol->GetType() != Opolygon) {
      	ApplicationOutput("not polygon");
      }
      
      AutoAlloc<Modeling> mod;
      if (!mod || !mod->InitObject(ToPoly(pol), 0)) {
      	ApplicationOutput("modeling alloc failed"); return 0;
      }
      
      pol->ResizeObject(4, 1);
      pol->SetName("POLY"_s);
      mod->SetPoint(pol, 3, Vector(-1, 0, 0));
      
      if(mod) mod->Commit(pol);
      
      EventAdd();
      

      Cube is created, resized, name is changed to "POLY" but zero changes from mod, there is error in console instead.
      I'm new to plugin development and don't know how to properly use API for such purposes.

      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        Hello and welcome to the forum,

        For your next threads, please help us keeping things organised and clean. I know it's not your priority but it really simplify our work here.

        • Q&A New Functionality.
        • How to Post Questions especially the tagging part.

        I've added marked this thread as a question so when you considered it as solved, please change the state 🙂

        In your code you Resize the object after initialized for the modeling command. That's why.

        but probably a simpler way to achieve what you want is to access the polygon's data. The PolygonObject is inherit from PointObject where you can retrieve the pointer of the points' vectors with GetPointW

        sometthing like so will work

        
        	Vector* padr{ pol->GetPointW() };
        	if (padr == nullptr)
        		return maxon::NullptrError(MAXON_SOURCE_LOCATION);
        
        	padr[3] = Vector(-2, 0, 0);
        

        You can have a look at our "roundtube" example in the sdk.zip file that ship with every Cinema 4D version. This example will show you how to create a primitive from scratch.

        Cheers,
        Manuel.

        MAXON SDK Specialist

        MAXON Registered Developer

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