McNeel Wiki
How To: Add a Brep Box Rhino
edit · print · help · all topics
Main Pages

AccuRender

Bongo

Brazil r/s

Developer

Flamingo

Penguin

Rhino Blogs

Rhino

Search

Languages

Česky

Deutsch

English

Español

Français

Italiano

Polish

日本語

한국어

中文(繁體)

 
.
DeveloperC++, .NET
SummaryDemonstrates how to add a Brep Box from a Rhino plug-in.

The openNURBS ON_BrepBox() will return an ON_Brep definition of a box. Note, ON_BrepBox() allocates memory for the ON_Brep, so the developer is reponsible for deleting the object when finished. In this example, we are adding the brep to Rhino, so Rhino will be responsible for deleting it.

C++

  CRhinoCommand::result CCommandTestSdk::RunCommand(const CRhinoCommandContext& context)
  {
    CRhinoCommand::result rc = CRhinoCommand::nothing;


    // define the corners of the box
    ON_3dPointArray corners;
    corners.Append( ON_3dPoint( 0.0,  0.0,  0.0) );
    corners.Append( ON_3dPoint(10.0,  0.0,  0.0) );
    corners.Append( ON_3dPoint(10.0, 10.0,  0.0) );
    corners.Append( ON_3dPoint( 0.0, 10.0,  0.0) );
    corners.Append( ON_3dPoint( 0.0,  0.0, 10.0) );
    corners.Append( ON_3dPoint(10.0,  0.0, 10.0) );
    corners.Append( ON_3dPoint(10.0, 10.0, 10.0) );
    corners.Append( ON_3dPoint( 0.0, 10.0, 10.0) );


    // Build the brep        
    ON_Brep* pBrep = ON_BrepBox( corners );
    if( pBrep )
    {
      CRhinoBrepObject* pObject = new CRhinoBrepObject();
      pObject->SetBrep( pBrep );
      if( context.m_doc.AddObject(pObject) )
      {
        context.m_doc.Redraw();
        rc = CRhinoCommand::success;
      }
      else
      {
        delete pObject;
        pObject = 0;
        rc = CRhinoCommand::failure;
      }
    }
    return rc;
  }

Note, if we had called CRhinoDoc::AddBrepObject() instead of CRhinoDoc::AddObject(), we would be responsible for deleting the brep (pBrep) because CRhinoDoc::AddBrepObject() makes a copy of the input brep.

VB.NET (Rhino 4)

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


    Dim rc As IRhinoCommand.result = IRhinoCommand.result.nothing
    ' define the corners of the box
    Dim corners(8) As On3dPoint
    corners(0) = New On3dPoint(0.0, 0.0, 0.0)
    corners(1) = New On3dPoint(10.0, 0.0, 0.0)
    corners(2) = New On3dPoint(10.0, 10.0, 0.0)
    corners(3) = New On3dPoint(0.0, 10.0, 0.0)
    corners(4) = New On3dPoint(0.0, 0.0, 10.0)
    corners(5) = New On3dPoint(10.0, 0.0, 10.0)
    corners(6) = New On3dPoint(10.0, 10.0, 10.0)
    corners(7) = New On3dPoint(0.0, 10.0, 10.0)


    ' Build the brep        
    Dim pBrep As OnBrep = OnUtil.ON_BrepBox(corners)
    If (pBrep IsNot Nothing) Then
      If (context.m_doc.AddBrepObject(pBrep) IsNot Nothing) Then
        context.m_doc.Redraw()
        rc = IRhinoCommand.result.success
      Else
        rc = IRhinoCommand.result.failure
      End If
    End If
    Return rc
  End Function

C# (Rhino 4)

  public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
  {
    IRhinoCommand.result rc = IRhinoCommand.result.nothing;
    // define the corners of the box
    On3dPoint[] corners = new On3dPoint[8];
    corners[0] = new On3dPoint(0.0, 0.0, 0.0);
    corners[1] = new On3dPoint(10.0, 0.0, 0.0);
    corners[2] = new On3dPoint(10.0, 10.0, 0.0);
    corners[3] = new On3dPoint(0.0, 10.0, 0.0);
    corners[4] = new On3dPoint(0.0, 0.0, 10.0);
    corners[5] = new On3dPoint(10.0, 0.0, 10.0);
    corners[6] = new On3dPoint(10.0, 10.0, 10.0);
    corners[7] = new On3dPoint(0.0, 10.0, 10.0);


    // Build the brep        
    OnBrep pBrep = OnUtil.ON_BrepBox(corners);
    if( pBrep != null )
    {
      if(context.m_doc.AddBrepObject(pBrep) != null)
      {
        context.m_doc.Redraw();
        rc = IRhinoCommand.result.success;
      }
      else
        rc = IRhinoCommand.result.failure;
    }
    return rc;
  }
rename · changes · history · subscriptions · lost and found · references · file upload