Site Tools


How To: Add a Torus to Rhino

Developer: C++
Summary: Demonstrates how to create a torus using ON_BrepTorus and add it to Rhino.

For more information on the ON_BrepTorus function, see it's definition in opennurbs_brep.h.

C++

CRhinoCommand::result CCommandTest::RunCommand(
        const CRhinoCommandContext& context 
        )
{
  double major_radius = 4.0;
  double minor_radius = 2.0;
  ON_Plane plane( ON_origin, ON_zaxis );
  ON_Circle circle( plane, major_radius );
  ON_Torus torus( circle, minor_radius );
  ON_Brep* brep = ON_BrepTorus( torus );
  if( brep )
  {
    CRhinoBrepObject* torus_object = new CRhinoBrepObject();
    torus_object->SetBrep( brep );
    if( context.m_doc.AddObject(torus_object) )
      context.m_doc.Redraw();
    else
      delete torus_object;
  }
  return CRhinoCommand::success;
}


developer/sdksamples/addtorus.txt ยท Last modified: 2020/08/14 (external edit)