Site Tools


Differences

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

Link to this comparison view

developer:sdksamples:convertarctonurbs [2015/09/14] (current)
Line 1: Line 1:
 +======Convert an Arc Curve to a NURBS Curve======
 +> **Developer:​** //​[[developer:​cplusplusplugins|C++]],​ [[developer:​dotnetplugins|.NET]]//​
 +> **Summary:​** //​Demonstrates how to convert an ON_ArcCurve object to an ON_NurbsCurve object.//
 +
 +=====Example=====
 +The following sample code demonstration of how to convert an ON_ArcCurve object to an ON_NurbsCurve object.
 +
 +====C++====
 +<code c++>
 +CRhinoCommand::​result CCommandTest::​RunCommand( const CRhinoCommandContext&​ context )
 +{
 +  CRhinoGetObject go;
 +  go.SetCommandPrompt( L"​Select arc to convert"​ );
 +  go.SetGeometryFilter( CRhinoGetObject::​curve_object );
 +  go.SetGeometryAttributeFilter( CRhinoGetObject::​open_curve );
 +  go.GetObjects( 1, 1 );
 +  if( go.CommandResult() != success )
 +    return go.CommandResult();​
 +
 +  const CRhinoObjRef&​ obj_ref = go.Object(0);​
 +  const CRhinoObject* obj = obj_ref.Object();​
 +  if( !obj )
 +    return failure;
 +
 +  const ON_ArcCurve* arc_crv = ON_ArcCurve::​Cast( obj_ref.Geometry() );
 +  if( !arc_crv )
 +  {
 +    RhinoApp().Print( L"​Curve is not an arc.\n"​ );
 +    return nothing;
 +  }
 +
 +  ON_NurbsCurve nurbs_crv;
 +  if( arc_crv->​GetNurbForm(nurbs_crv) && nurbs_crv.IsValid() )
 +  {
 +    ON_3dmObjectAttributes attribs = obj->​Attributes();​
 +    context.m_doc.AddCurveObject( nurbs_crv, &​attribs );
 +    context.m_doc.DeleteObject( obj_ref );
 +    context.m_doc.Redraw();​
 +    return success;
 +  }
 +
 +  return failure;
 +}
 +</​code>​
 +
 +==== VB.NET ====
 +<code vb>
 +Public Overrides Function RunCommand(ByVal context As IRhinoCommandContext) _
 +  As IRhinoCommand.result
 +  Dim go As New MRhinoGetObject()
 +  go.SetCommandPrompt("​Select arc to convert"​)
 +  go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object)
 +  go.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.open_curve)
 +  go.GetObjects(1,​ 1)
 +  If (go.CommandResult() <> IRhinoCommand.result.success) Then
 +    Return go.CommandResult()
 +  End If
 +
 +  Dim obj_ref As MRhinoObjRef = go.Object(0)
 +  Dim arc_crv As IOnArcCurve = OnArcCurve.ConstCast(obj_ref.Geometry())
 +  If (arc_crv Is Nothing) Then
 +    RhUtil.RhinoApp().Print("​Curve is not an arc." + vbCrLf)
 +    Return IRhinoCommand.result.nothing
 +  End If
 +
 +  Dim nurbs_crv As New OnNurbsCurve()
 +  If (arc_crv.GetNurbForm(nurbs_crv) > 0 And nurbs_crv.IsValid()) Then
 +    context.m_doc.ReplaceObject(obj_ref,​ nurbs_crv)
 +    context.m_doc.Redraw()
 +    Return IRhinoCommand.result.success
 +  End If
 +  Return IRhinoCommand.result.failure
 +End Function
 +</​code>​
 +
 +==== C# ====
 +<code c#>
 +public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
 +{
 +  MRhinoGetObject go = new MRhinoGetObject();​
 +  go.SetCommandPrompt( "​Select arc to convert"​ );
 +  go.SetGeometryFilter( IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object );
 +  go.SetGeometryAttributeFilter( IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.open_curve );
 +  go.GetObjects( 1, 1 );
 +  if( go.CommandResult() != IRhinoCommand.result.success )
 +    return go.CommandResult();​
 +
 +  MRhinoObjRef obj_ref = go.Object(0);​
 +  IOnArcCurve arc_crv = OnArcCurve.ConstCast(obj_ref.Geometry());​
 +  if( arc_crv == null )
 +  {
 +    RhUtil.RhinoApp().Print( "Curve is not an arc.\n"​ );
 +    return IRhinoCommand.result.nothing;​
 +  }
 +
 +  OnNurbsCurve nurbs_crv = new OnNurbsCurve();​
 +  if( arc_crv.GetNurbForm(ref nurbs_crv) > 0 && nurbs_crv.IsValid() )
 +  {
 +    context.m_doc.ReplaceObject(obj_ref,​ nurbs_crv);
 +    context.m_doc.Redraw();​
 +    return IRhinoCommand.result.success;​
 +  }
 +  return IRhinoCommand.result.failure;​
 +}
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer cplusplus dotnet}}
  
developer/sdksamples/convertarctonurbs.txt ยท Last modified: 2015/09/14 (external edit)