how to bevel edges?



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

    On 08/11/2010 at 12:05, xxxxxxxx wrote:

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

    ---------
    Hi,

    i am trying to figure out how to bevel but i cant get it to work. its simply crashing...
    this is some test code with which i am trying to figure it out.

      
    BaseObject *test::GetVirtualObjects(PluginObject *op, HierarchyHelp *hh)  
    {  
      BaseDocument* doc = op->GetDocument();  
      BaseObject* tempObj = BaseObject::Alloc(Ocube);  
      ModelingCommandData cd;  
      BaseContainer* mbc = NULL;  
      cd.doc = doc;  
      cd.op = tempObj;  
      if (SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, cd))  
      {  
          blDelete(tempObj);  
          tempObj = static_cast<BaseObject*>(cd.result->GetIndex(0));  
          tempObj->InsertUnderLast(main);  
      }  
    ///until here it works  
      cd.op = tempObj;  
      mbc->SetParameter(MDATA_BEVEL_OFFSET2,GeData(1.0)); //crashes if this line is in  
      if (SendModelingCommand(450000005, cd))  
      {  
            GePrint("done");  
      }  
      return main;  
    }  
    

    any help would be cool

    cheers,
    ello



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

    On 09/11/2010 at 13:26, xxxxxxxx wrote:

    mbc = NULL?

    Of course it crashes.  You are trying to call NULL->SetParameter().

    Simply create a BaseContainer:

    BaseContainer mbc;

    and *you must add it* to the ModelingCommandData cd.bc if you want the parameter acted upon:

    cd.bc = &mbc;



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

    On 09/11/2010 at 22:59, xxxxxxxx wrote:

    omg :) thank you very much!



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

    On 11/11/2010 at 11:41, xxxxxxxx wrote:

    hi again.. any ideas why SendModelingCommand would return false after i fixed the previous errors?
    no beveling is done.. but no error, no crash, either..

    thanks in advance.
    cheers,
    ello



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

    On 11/11/2010 at 21:13, xxxxxxxx wrote:

    I'm applying the Beveling tool like this:

        bc.SetReal(MDATA_BEVEL_ANGLE,                89.0);  
      bc.SetReal(MDATA_BEVEL_OFFSET1,                maxBevel);    // Up  
      bc.SetReal(MDATA_BEVEL_VARIANCE1,            0.0);  
      bc.SetReal(MDATA_BEVEL_OFFSET2,                maxBevel);    // In  
      bc.SetReal(MDATA_BEVEL_VARIANCE2,            0.0);  
      bc.SetLong(MDATA_BEVEL_SUBDIVISION,            0L);  
      bc.SetBool(MDATA_BEVEL_CREATENGONS,            FALSE);  
      bc.SetBool(MDATA_BEVEL_MODE,                MDATA_BEVEL_MODE_LINEAR);  
      bc.SetBool(MDATA_BEVEL_PRESERVEGROUPS,        TRUE);  
      if (!SendModelingCommand(ID_MODELING_BEVEL_TOOL, mcd))    return FALSE;  
    

    Also note that you will need to set the ModelingCommandData mode.  If you are using a polygon selection, you must select the polygons and set mcd.mode to MODELINGCOMMANDMODE_POLYGONSELECTION (R12 enum).

    Don't forget the mcd.doc and mcd.op as well!

    Hope that helps! :)



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

    On 12/11/2010 at 13:52, xxxxxxxx wrote:

    hi there.. i tried and it still doesnt work... the SendModelingCommand still returns 0...
    here is my complete code, maybe it is something other??

      
      
    BaseObject *test::GetVirtualObjects(PluginObject *op, HierarchyHelp *hh)  
    {  
      BaseContainer* data = op->GetDataInstance();  
      BaseDocument* doc = op->GetDocument();  
      BaseObject* main = NULL;  
      BaseObject* res = NULL;  
      BaseObject* tempObj = NULL;  
      ModelingCommandData cd;  
      BaseContainer mbc;  
      ObjectColorProperties prop;  
      
      
      main = BaseObject::Alloc(Onull);  
      if (!main) goto Error;  
      main->SetName(pluginName);  
      main->SetPos(Vector(0));  
      
      Bool dirty = FALSE;      
      dirty = op->CheckCache(hh) || op->IsDirty((DIRTY_DATA|DIRTY_CHILDREN));  
      if (!dirty)   
      {  
          blDelete(main);                  
          return op->GetCache(hh);  
      }  
      
      tempObj = BaseObject::Alloc(Ocube);  
      
      cd.doc = doc;  
      cd.op = tempObj;  
      if (SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, cd))  
      {  
          blDelete(tempObj);  
          res = static_cast<BaseObject*>(cd.result->GetIndex(0));  
          res->InsertUnderLast(main);  
      }  
      
      cd.doc = doc;  
      cd.op = res;  
      mbc.SetReal(MDATA_BEVEL_ANGLE,                89.0);  
      mbc.SetReal(MDATA_BEVEL_OFFSET1,                1.0);    // Up  
      mbc.SetReal(MDATA_BEVEL_VARIANCE1,            0.0);  
      mbc.SetReal(MDATA_BEVEL_OFFSET2,                1.0);    // In  
      mbc.SetReal(MDATA_BEVEL_VARIANCE2,            0.0);  
      mbc.SetLong(MDATA_BEVEL_SUBDIVISION,            0L);  
      mbc.SetBool(MDATA_BEVEL_CREATENGONS,            FALSE);  
      mbc.SetBool(MDATA_BEVEL_MODE,                MDATA_BEVEL_MODE_LINEAR);  
      mbc.SetBool(MDATA_BEVEL_PRESERVEGROUPS,        TRUE);  
      cd.bc = &mbc;  
      if (!SendModelingCommand(ID_MODELING_BEVEL_TOOL, cd))    GePrint("no bevel");  
      
      prop.usecolor = ID_BASEOBJECT_USECOLOR_AUTOMATIC;  
      prop.color = Vector(64,128,255);  
      prop.xray = FALSE;  
      main->SetColorProperties(&prop);  
      return main;  
      
    Error:  
      if (main) blDelete(main);  
      return NULL;  
    }  
    


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

    On 12/11/2010 at 13:58, xxxxxxxx wrote:

    GetVirtualObects() - there's your problem.  If you search the forum (and read the docs on this) you will find out that you are *forbidden* to do anything that changes the scene within this method.  If you need to do this stuff, you must first create a temporary document, clone/create the object to be modified, add the object to the temp. document, and do the changes there.  Then you can remove it from the temp. document and add it to the output of GetVirtualObjects().

    ETA1: Sorry that I didn't notice this in your first post.

    ETA2: Also note that you are assuming that 'res' from CURRENTSTATETOOBJECT is not NULL.  You must always, always check for valid pointers.  This might be why your second SendModelingCommand() is failing (mcd.op = res = NULL).

    ETA3: Also, the doc for the object in the ModelingCommandData must be the doc in which the object resides.  Since you cannot modify the one from op->GetDocument(), you will use the temporary one mentioned above.  The object must be inserted into that document:

    AutoAlloc<BaseDocument> tmpDoc;
    if (!tmpDoc) return NULL;  // etc. considering cleanup
    BaseObject* tempObj = BaseObject::Alloc(Ocube);
    if (!tempObj) return NULL;
    tmpDoc->InsertObject(tempObj, NULL, NULL, FALSE);
    // Now do your magic
    // ---
    // Done with magic
    res->Remove(); // if it needed to be inserted into tmpDoc!
    res->InsertUnderLast(main);

    Note that you will need to insert 'res' into the same tmpDoc document to do further work on it - as necessary.  Some SendModelingCommands don't require a doc and object be in a doc to work while others do.  CURRENTSTATETOOBJECT does, beveling might not.



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

    On 13/11/2010 at 05:55, xxxxxxxx wrote:

    thank you very much for your help. i hope i'll get this working..

    cheers,
    ello



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

    On 23/11/2010 at 13:26, xxxxxxxx wrote:

    hmpf... i still wasnt able to get it working. still the modelling command returns false.
    any ideas??

      
      if (!tmpDoc) goto Error;    
      tempObj = BaseObject::Alloc(Ocube);  
      if (!tempObj) goto Error;  
      tmpDoc->InsertObject(tempObj, NULL, NULL, FALSE);  
      
      cd.doc = tmpDoc;  
      cd.op = tempObj;  
      if (SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, cd))  
      {  
          GePrint("step1");  
          res = static_cast<BaseObject*>(cd.result->GetIndex(0));  
          if (res)  
          {  
              tmpDoc->InsertObject(res, NULL, NULL, FALSE);  
              cd2.doc = tmpDoc;  
              cd2.op = res;  
              mbc.SetReal(MDATA_BEVEL_ANGLE,                89.0);  
              mbc.SetReal(MDATA_BEVEL_OFFSET1,                1.0);    // Up  
              mbc.SetReal(MDATA_BEVEL_VARIANCE1,            0.0);  
              mbc.SetReal(MDATA_BEVEL_OFFSET2,                1.0);    // In  
              mbc.SetReal(MDATA_BEVEL_VARIANCE2,            0.0);  
              mbc.SetLong(MDATA_BEVEL_SUBDIVISION,            0L);  
              mbc.SetBool(MDATA_BEVEL_CREATENGONS,            FALSE);  
              mbc.SetBool(MDATA_BEVEL_MODE,                MDATA_BEVEL_MODE_LINEAR);  
              mbc.SetBool(MDATA_BEVEL_PRESERVEGROUPS,        TRUE);  
              cd2.bc = &mbc;  
              cd2.mode = MODIFY_ALL;  
                
              if (!SendModelingCommand(ID_MODELING_BEVEL_TOOL, cd2))    GePrint("failed 2");  
              else   
              {  
                  GePrint("step2");  
                  res = static_cast<BaseObject*>(cd.result->GetIndex(0));  
                  if (res)  
                      res->InsertUnderLast(main);  
              }  
          }  
      }  
    

Log in to reply