Code to extrude a cube doesn't work!



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 01/06/2008 at 09:27, xxxxxxxx wrote:

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

    ---------
    Hi. I'm still trying to write some code in c++, which creates a cube and extrude one side. Finally I managed to write the code so it doesn't crash any more, but there is still no extruded cube in Cinema 4d. Instead there's only an object which seems to be empty.

    Here's the code:

    BaseObject* extrudierterWuerfel::GetVirtualObjects(BaseObject *op, HierarchyHelp *hh)
    {
         BaseDocument *doc = op->GetDocument();
         BaseDocument *copydoc=doc->Alloc();

    BaseObject *cloned = BaseObject::Alloc(Ocube);

    PolygonObject *poly=NULL;

    copydoc->InsertObject(cloned,NULL,NULL,FALSE);
         copydoc->InsertObject(poly,NULL,NULL,FALSE);

    ModelingCommandData cd,cd2,cd3;
         cd.doc     = copydoc;
         cd.op     = cloned;
         
         if (!SendModelingCommand(MCOMMAND_MAKEEDITABLE, cd)) return NULL;

    poly=static_cast<PolygonObject*>(cd.result->GetIndex(0));

    copydoc->SetMode(Mpolygons);

    //Select all
         ModelingCommandData cd1;
         cd1.doc = copydoc;
         cd1.op = poly;
         cd1.mode = MODIFY_POLYGONSELECTION;
         if (!SendModelingCommand(MCOMMAND_SELECTALL, cd1)) GePrint("could not select all");

    GePrint("Selektion geschafft!");
         BaseContainer bc;               
         bc.SetData(MDATA_EXTRUDE_OFFSET, 50);          
         
         ModelingCommandData extrusionmcd;

    extrusionmcd.bc=&bc;
         extrusionmcd.doc=copydoc;
         extrusionmcd.op=poly;
         extrusionmcd.mode=MODIFY_ALL;

    poly=ToPoly(SendModelingCommand(ID_MODELING_EXTRUDE_TOOL, extrusionmcd));

    return poly;     
    }

    To make a guess: Is it maybe because poly=static_cast<PolygonObject*>(cd.result->GetIndex(0)); only assigns a little something, not the whole cube?

    Another problem I have is, that "Unable to open file *.res" appears everytime I run the plugin. Is it possible that this causes my problem? How do I make such a *.res-file?

    Thanks
    Basti



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 02/06/2008 at 01:02, xxxxxxxx wrote:

    You have to insert the poly object into the cloned document AFTER you made the cube editable. Currently you insert a NULL pointer into the document.

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 02/06/2008 at 02:00, xxxxxxxx wrote:

    Uh, youre right, thats definately a problem!

    I now moved "copydoc->InsertObject(poly,NULL,NULL,FALSE);" to the line after "poly=static_cast<PolygonObject*>(cd.result->GetIndex(0));", but there has to be another fault, because nothing changed. There is still nothing in the created object.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/06/2008 at 02:51, xxxxxxxx wrote:

    Got it!
    This is the working code:

    BaseObject* extrudierterWuerfel::GetVirtualObjects(BaseObject *op, HierarchyHelp *hh)
    {
         BaseDocument *doc = op->GetDocument();
         BaseDocument *copydoc=doc->Alloc();

    BaseObject *cloned = BaseObject::Alloc(Ocube);     
         
         PolygonObject *poly=NULL;

    copydoc->InsertObject(cloned,NULL,NULL,FALSE);

    ModelingCommandData cd;
         cd.doc     = copydoc;
         cd.op     = cloned;

    if (!SendModelingCommand(MCOMMAND_MAKEEDITABLE, cd))
          {
               GePrint("MAKEEDITABLE nicht erfolgreich");
               return NULL;
          }

    poly=static_cast<PolygonObject*>(cd.result->GetIndex(0));

    copydoc->InsertObject(poly,NULL,NULL,FALSE);

    copydoc->SetMode(Mpolygons);

    // ================== Selektieren ============================

    BaseSelect* selection;

    selection = poly->GetPolygonS();

    selection->Select(0);               // 0. Polygon selektieren

    // =========== Extrudieren des ausgewählten Polygons ==========

    BaseContainer bc1;               // Einstellungen für die Extrusion
         bc1.SetData(MDATA_EXTRUDE_OFFSET, 50);          // Länge der Extrusion     
         bc1.SetData(MDATA_EXTRUDE_PRESERVEGROUPS, FALSE);
         
         ModelingCommandData extrusionmcd;

    extrusionmcd.bc=&bc1;
         extrusionmcd.doc=copydoc;
         extrusionmcd.op=poly;
         extrusionmcd.mode=MODIFY_POLYGONSELECTION;

    if(!SendModelingCommand(ID_MODELING_EXTRUDE_TOOL, extrusionmcd))
         {
              GePrint("Extrusion nicht erfolgreich!");     //Extrusion
         }
         else
         {
              GePrint("Extrusion erfolgreich!");
         }

    return poly;
    }


Log in to reply