Sdk Extend Surface
Last changed: stevebaer-63.226.222.185

.
DeveloperC++, .NET
SummaryDemonstrates how to use RhinoExtendSurface() to extend a surface object.

C++

  CRhinoCommand::result CCommandTest::RunCommand( const CRhinoCommandContext& context )
  {
    CRhinoGetObject go;
    go.SetCommandPrompt( L"Select edge of surface to extend" );
    go.SetGeometryFilter(CRhinoGetObject::edge_object);
    go.SetGeometryAttributeFilter( CRhinoGetObject::edge_curve );
    go.GetObjects( 1, 1 );
    if( go.CommandResult() != CRhinoCommand::success )
      return go.CommandResult();


    const CRhinoObjRef& objref = go.Object(0);
    const ON_Surface* srf = objref.Surface();
    if( !srf )
    {
      RhinoApp().Print( L"Unable to extend polysurfaces.\n" );
      return CRhinoCommand::nothing;                
    }


    const ON_Brep* brep = objref.Brep();
    const ON_BrepFace* face = objref.Face();
    if( !brep || !face || face->m_face_index < 0 )
      return CRhinoCommand::failure;


    if( !brep->IsSurface() )
    {
      RhinoApp().Print( L"Unable to extend trimmed surfaces.\n" );
      return CRhinoCommand::nothing;                
    }


    const ON_BrepTrim* trim = objref.Trim();
    if( !trim )
      return CRhinoCommand::failure;


    ON_Surface::ISO edge_index( trim->m_iso );
    int dir = edge_index % 2;
    if( srf->IsClosed(1-dir) )
    {
      RhinoApp().Print(L"Unable to extend surface at seam.\n" );
      return CRhinoCommand::nothing;        
    }
    if( edge_index < ON_Surface::W_iso || edge_index > ON_Surface::N_iso )
    {
      RhinoApp().Print( L"Selected edge must be an underlying surface edge.\n" );
      return CRhinoCommand::nothing;        
    }


    ON_Surface* myface = srf->DuplicateSurface();
    if( !myface )
      return CRhinoCommand::failure;


    bool rc = RhinoExtendSurface( myface, edge_index, 5.0, true);        
    if( rc )
    {
      ON_Brep* mybrep = new ON_Brep();
      mybrep->Create( myface );
      CRhinoBrepObject* obj = new CRhinoBrepObject();
      obj->SetBrep( mybrep );
      context.m_doc.ReplaceObject( CRhinoObjRef(objref.Object()), obj );
      context.m_doc.Redraw();
    }
    return CRhinoCommand::success;
  }

VB.NET (Rhino 4)

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


    Dim go As New MRhinoGetObject
    go.SetCommandPrompt("Select edge of surface to extend")
    go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.edge_object)
    go.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.edge_curve)
    go.GetObjects(1, 1)
    If (go.CommandResult() <> IRhinoCommand.result.success) Then
      Return go.CommandResult()
    End If


    Dim objref As IRhinoObjRef = go.Object(0)
    Dim srf As IOnSurface = objref.Surface()
    If (srf Is Nothing) Then
      RhUtil.RhinoApp().Print("Unable to extend polysurfaces." + vbCrLf)
      Return IRhinoCommand.result.nothing
    End If


    Dim brep As IOnBrep = objref.Brep()
    Dim face As IOnBrepFace = objref.Face()
    If (brep Is Nothing Or face Is Nothing) Then Return IRhinoCommand.result.failure
    If (face.m_face_index < 0) Then Return IRhinoCommand.result.failure


    If (Not brep.IsSurface()) Then
      RhUtil.RhinoApp().Print("Unable to extend trimmed surfaces." + vbCrLf)
      Return IRhinoCommand.result.nothing
    End If


    Dim trim As IOnBrepTrim = objref.Trim()
    If (trim Is Nothing) Then Return IRhinoCommand.result.failure


    Dim edge_index As IOnSurface.ISO = trim.m_iso
    Dim dir As Integer = edge_index Mod 2
    If (srf.IsClosed(1 - dir)) Then
      RhUtil.RhinoApp().Print("Unable to extend surface at seam." + vbCrLf)
      Return IRhinoCommand.result.nothing
    End If


    If (edge_index < IOnSurface.ISO.W_iso Or edge_index > IOnSurface.ISO.N_iso) Then
      RhUtil.RhinoApp().Print("Selected edge must be an underlying surface edge." + vbCrLf)
      Return IRhinoCommand.result.nothing
    End If


    Dim myface As OnSurface = srf.DuplicateSurface()
    If (myface Is Nothing) Then
      Return IRhinoCommand.result.failure
    End If


    Dim rc As Boolean = RhUtil.RhinoExtendSurface(myface, edge_index, 5.0, True)
    If (rc) Then
      Dim mybrep As New OnBrep()
      mybrep.Create(myface)
      Dim obj As New MRhinoBrepObject()
      obj.SetBrep(mybrep)
      context.m_doc.ReplaceObject(New MRhinoObjRef(objref.Object()), obj)
      context.m_doc.Redraw()
    End If
    Return IRhinoCommand.result.success
  End Function

C# (Rhino 4)

  public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
  {
    MRhinoGetObject go = new MRhinoGetObject();
    go.SetCommandPrompt("Select edge of surface to extend");
    go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.edge_object);
    go.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.edge_curve);
    go.GetObjects(1, 1);
    if(go.CommandResult() != IRhinoCommand.result.success)
      return go.CommandResult();


    IRhinoObjRef objref = go.Object(0);
    IOnSurface srf = objref.Surface();
    if(srf == null)
    {
      RhUtil.RhinoApp().Print("Unable to extend polysurfaces.\n");
      return IRhinoCommand.result.nothing;
    }


    IOnBrep brep = objref.Brep();
    IOnBrepFace face = objref.Face();
    if(brep==null || face==null)
      return IRhinoCommand.result.failure;
    if(face.m_face_index < 0)
      return IRhinoCommand.result.failure;


    if( !brep.IsSurface())
    {
      RhUtil.RhinoApp().Print("Unable to extend trimmed surfaces.\n");
      return IRhinoCommand.result.nothing;
    }


    IOnBrepTrim trim = objref.Trim();
    if(trim == null)
      return IRhinoCommand.result.failure;


    IOnSurface.ISO edge_index = trim.m_iso;
    int dir = (int)edge_index % 2;
    if(srf.IsClosed(1 - dir))
    {
      RhUtil.RhinoApp().Print("Unable to extend surface at seam.\n");
      return IRhinoCommand.result.nothing;
    }


    if(edge_index<IOnSurface.ISO.W_iso || edge_index>IOnSurface.ISO.N_iso)
    {
      RhUtil.RhinoApp().Print("Selected edge must be an underlying surface edge.\n");
      return IRhinoCommand.result.nothing;
    }


    OnSurface myface = srf.DuplicateSurface();
    if(myface==null)
      return IRhinoCommand.result.failure;


    bool rc = RhUtil.RhinoExtendSurface(ref myface, edge_index, 5.0, true);
    if(rc)
    {
      OnBrep mybrep = new OnBrep();
      mybrep.Create(myface);
      MRhinoBrepObject obj = new MRhinoBrepObject();
      obj.SetBrep(mybrep);
      context.m_doc.ReplaceObject(new MRhinoObjRef(objref.Object()), obj);
      context.m_doc.Redraw();
    }
    return IRhinoCommand.result.success;
  }