Add Sphere
Last changed: stevebaer-204.177.179.132

.
SummaryDemonstrates how to create a sphere using ON_RevSurface and add it to Rhino.
DeveloperC++, .NET

Note, spheres can also be created using the ON_BrepSphere function. See opennurbs_brep.h for more information.

C++

  CRhinoCommand::result CCommandTest::RunCommand( const CRhinoCommandContext& context )
  {
    CRhinoCommand::result rc = CRhinoCommand::cancel;


    ON_3dPoint center( 0.0, 0.0, 0.0 );
    double radius = 5.0;
    ON_Sphere sphere( center, radius );
    ON_RevSurface* sphere_srf = sphere.RevSurfaceForm();
    if( !sphere_srf )
      return rc;


    CRhinoSurfaceObject* sphere_obj = new CRhinoSurfaceObject();
    sphere_obj->SetSurface( sphere_srf );


    if( context.m_doc.AddObject(sphere_obj) )
    {
      context.m_doc.Redraw();
      rc = CRhinoCommand::success;
    }
    else
    {
      delete sphere_obj;
      sphere_obj = NULL;
    }


    return rc;
  }

VB.NET (Rhino 4)

  Public Overrides Function RunCommand(ByVal context As IRhinoCommandContext)_
    As IRhinoCommand.result


    Dim rc As IRhinoCommand.result = IRhinoCommand.result.cancel
    Dim center As New On3dPoint(0, 0, 0)
    Dim radius As Double = 5
    Dim sphere As New OnSphere(center, radius)


    Dim sphere_srf As OnRevSurface = sphere.RevSurfaceForm()
    If (sphere_srf Is Nothing) Then
      Return rc
    End If


    Dim sphere_obj As New MRhinoSurfaceObject()
    sphere_obj.SetSurface(sphere_srf)


    If (context.m_doc.AddObject(sphere_obj)) Then
      context.m_doc.Redraw()
      rc = IRhinoCommand.result.success
    End If
    Return rc
  End Function

C# (Rhino 4)

  public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
  {
    IRhinoCommand.result rc = IRhinoCommand.result.cancel;
    On3dPoint center = new On3dPoint(0, 0, 0);
    double radius = 5;
    OnSphere sphere = new OnSphere(center, radius);


    OnRevSurface sphere_srf = sphere.RevSurfaceForm();
    if( sphere_srf == null )
      return rc;


    MRhinoSurfaceObject sphere_obj = new MRhinoSurfaceObject();
    sphere_obj.SetSurface(sphere_srf);


    if(context.m_doc.AddObject(sphere_obj))
    {
      context.m_doc.Redraw();
      rc = IRhinoCommand.result.success;
    }
    return rc;
  }