Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:sdksamples:edgesrf [2015/09/14] (current)
Line 1: Line 1:
 +====== How To: Create a Surface from Edge Curves ======
 +====== C++, .NET ======
 +> **Summary:​** //​Demonstrates how to create a surface object from four edge curves.//
 +> **NOTICE:** //The Rhino.NET SDK is deprecated in Rhino 5.  This example adapted for the new RhinoCommon SDK is [[developer:​rhinocommonsamples:​edgesrf|here]]//​
 +
 +===== C++ =====
 +<code c++>
 +CRhinoCommand::​result CCommandTest::​RunCommand(const CRhinoCommandContext&​ context)
 +{
 +  // Pick four curve objects
 +  CRhinoGetObject go;
 +  go.SetCommandPrompt( L"​Select 4 curves"​ );
 +  go.SetGeometryFilter( CRhinoGetObject::​curve_object);​
 +  go.GetObjects( 4, 4 );
 +  if( go.CommandResult() != CRhinoCommand::​success )
 +    return go.CommandResult();​
 +
 +  // Validate results
 +  int i, count = go.ObjectCount();​
 +  if( count != 4 )
 +    return CRhinoCommand::​failure;​
 +
 +  ON_NurbsCurve nc[4];
 +  // Get nurb form of each curve
 +  for( i = 0; i < count; i++)
 +  {
 +    const ON_Curve* crv = go.Object(i).Curve();​
 +    if( !crv )
 +      return CRhinoCommand::​failure;​
 +    if( !crv->​GetNurbForm(nc[i]) )
 +      return CRhinoCommand::​failure;​
 +  }
 +
 +  // Create the surface
 +  ON_Brep* brep = RhinoCreateEdgeSrf( 4, nc );
 +  if( !brep )
 +  {
 +    RhinoApp().Print( L"​Unable to create surface.\n"​ );
 +    return CRhinoCommand::​failure;​
 +  }
 +
 +  // Ready new brep object
 +  CRhinoBrepObject* obj = new CRhinoBrepObject;​
 +  obj->​SetBrep( brep );
 +
 +  // Add new objet to document
 +  if( !context.m_doc.AddObject( obj ) )
 +  {
 +    delete obj;
 +    RhinoApp().Print( L"​Unable to create surface.\n"​ );
 +    return CRhinoCommand::​failure;​
 +  }
 +
 +  context.m_doc.Redraw();​
 +  return CRhinoCommand::​success;​
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Overrides Function RunCommand(ByVal context As IRhinoCommandContext)_
 +  As IRhinoCommand.result
 +  ' Pick four curve objects
 +  Dim go As New MRhinoGetObject()
 +  go.SetCommandPrompt("​Select 4 curves"​)
 +  go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object)
 +  go.GetObjects(4,​ 4)
 +  If (go.CommandResult() <> IRhinoCommand.result.success) Then Return go.CommandResult()
 +
 +  ' Validate results
 +  Dim count As Integer = go.ObjectCount()
 +  If (count <> 4) Then Return IRhinoCommand.result.failure
 +
 +  Dim nc(3) As OnNurbsCurve
 +  For i As Integer = 0 To 3
 +    nc(i) = New OnNurbsCurve()
 +  Next
 +
 +  ' Get nurb form of each curve
 +  For i As Integer = 0 To count - 1
 +    Dim crv As IOnCurve = go.Object(i).Curve()
 +    If (crv Is Nothing) Then Return IRhinoCommand.result.failure
 +    If (crv.GetNurbForm(nc(i)) = 0) Then Return IRhinoCommand.result.failure
 +  Next
 +
 +  ' Create the surface
 +  Dim brep As OnBrep = RhUtil.RhinoCreateEdgeSrf(nc)
 +  If (brep Is Nothing) Then
 +    RhUtil.RhinoApp.Print("​Unable to create surface."​ + vbCrLf)
 +    Return IRhinoCommand.result.failure
 +  End If
 +
 +  ' Ready new brep object
 +  Dim obj As New MRhinoBrepObject()
 +  obj.SetBrep(brep)
 +
 +  ' Add new object to document
 +  If (Not context.m_doc.AddObject(obj)) Then
 +    RhUtil.RhinoApp.Print("​Unable to create surface."​ + vbCrLf)
 +    Return IRhinoCommand.result.failure
 +  End If
 +
 +  context.m_doc.Redraw()
 +  Return IRhinoCommand.result.success
 +End Function
 +</​code>​
 +===== C# =====
 +<code c#>
 +public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
 +{
 +  // Pick four curve objects
 +  MRhinoGetObject go = new MRhinoGetObject();​
 +  go.SetCommandPrompt("​Select 4 curves"​);​
 +  go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);​
 +  go.GetObjects(4,​ 4);
 +  if(go.CommandResult() != IRhinoCommand.result.success)
 +    return go.CommandResult();​
 +
 +  // Validate results
 +  int count = go.ObjectCount();​
 +  if(count != 4)
 +    return IRhinoCommand.result.failure;​
 +  OnNurbsCurve[] nc = new OnNurbsCurve[4];​
 +  for( int i=0; i<4; i++ )
 +    nc[i] = new OnNurbsCurve();​
 +
 +  // Get nurb form of each curve
 +  for( int i=0; i<count; i++ )
 +  {
 +    IOnCurve crv = go.Object(i).Curve();​
 +    if(crv == null)
 +      return IRhinoCommand.result.failure;​
 +    if(crv.GetNurbForm(ref nc[i]) == 0)
 +      return IRhinoCommand.result.failure;​
 +  }
 +
 +  // Create the surface
 +  OnBrep brep = RhUtil.RhinoCreateEdgeSrf(nc);​
 +  if(brep == null)
 +  {
 +    RhUtil.RhinoApp().Print("​Unable to create surface.\n"​);​
 +    return IRhinoCommand.result.failure;​
 +  }
 +
 +  // Add new object to document
 +  if(context.m_doc.AddBrepObject(brep) == null)
 +  {
 +    RhUtil.RhinoApp().Print("​Unable to create surface.\n"​);​
 +    return IRhinoCommand.result.failure;​
 +  }
 +  context.m_doc.Redraw();​
 +  return IRhinoCommand.result.success;​
 +}
 +
 +</​code>​
 +
 +
 +{{tag>​Developer cplusplus dotnet}}
  
developer/sdksamples/edgesrf.txt ยท Last modified: 2015/09/14 (external edit)