Site Tools


Differences

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

Link to this comparison view

developer:sdksamples:pickpoint [2015/09/14] (current)
Line 1: Line 1:
 +====== How To: Pick Point Objects ======
 +====== C++, .NET ======
 +> **Summary:​** //​Demonstrates how to use CRhinoGetObject to pick point objects.//
 +> **NOTICE:** //The Rhino.NET SDK is deprecated in Rhino 5.  This example adapted for the new RhinoCommon SDK is [[developer:​rhinocommonsamples:​pickpoint|here]]//​
 +
 +If you need the user to define a 3D point location, you can use a CRhinoGetPoint object. But, if the points already exist as objects in Rhino, you will need to use a CRhinoGetObject object to pick them. Then, you can determine the 3D coordinates of that point object.
 +
 +===== C++ =====
 +<code c++>
 +</​code>​
 +
 +<code c++>
 +CRhinoGetObject go;
 +go.SetCommandPrompt( L"​Select point" );
 +go.SetGeometryFilter( CRhinoGetObject::​point_object );
 +CRhinoGet::​result res = go.GetObjects( 1, 1 );
 +if( res == CRhinoGet::​object )
 +{
 +  const CRhinoObjRef&​ objref = go.Object(0);​
 +  const ON_Point* pt = objref.Point();​
 +  if( pt )
 +    RhinoApp().Print(L"​Point:​ %f,​%f,​%f",​ pt->​point.x,​ pt->​point.y,​ pt->​point.z);​
 +}
 +
 +</​code>​
 +If you needed access to the CRhinoPointObject object, you could do this:
 +
 +
 +<code c++>
 +CRhinoGetObject go;
 +go.SetCommandPrompt( L"​Select point" );
 +go.SetGeometryFilter( CRhinoGetObject::​point_object );
 +CRhinoGet::​result res = go.GetObjects( 1, 1 );
 +if( res == CRhinoGet::​object )
 +{
 +  const CRhinoObjRef&​ objref = go.Object(0);​
 +  const CRhinoPointObject* point_object = CRhinoPointObject::​Cast( objref.Object() );
 +  if( point_object )
 +  {
 +    const ON_Point&​ pt = point_object->​Point();​
 +    RhinoApp().Print(L"​Point:​ %f,​%f,​%f",​ pt.point.x, pt.point.y, pt.point.z);​
 +  }
 +}
 +
 +</​code>​
 +Here is how you can pick one or more point objects:
 +
 +
 +<code c++>
 +CRhinoGetObject go;
 +go.SetCommandPrompt( L"​Select points"​ );
 +go.SetGeometryFilter( CRhinoGetObject::​point_object );
 +CRhinoGet::​result res = go.GetObjects( 1, 0 );
 +if( res == CRhinoGet::​object )
 +{
 +  int i;
 +  for( i = 0; i < go.ObjectCount();​ i++ )
 +  {
 +    const CRhinoObjRef&​ objref = go.Object(i);​
 +    const ON_Point* point = objref.Point();​
 +    if( point )
 +      RhinoApp().Print( L"​Point %d: %f,​%f,​%f",​
 +                        i,
 +                        point->​point.x,​
 +                        point->​point.y,​
 +                        point->​point.z );
 +  }
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Overrides Function RunCommand(ByVal context As IRhinoCommandContext)_
 +  As RMA.Rhino.IRhinoCommand.result
 +
 +  Dim go As New MRhinoGetObject()
 +  go.SetCommandPrompt("​Select point"​)
 +  go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.point_object)
 +  Dim res As IRhinoGet.result = go.GetObjects(1,​ 1)
 +  If (res = IRhinoGet.result.object) Then
 +    Dim objref As IRhinoObjRef = go.Object(0)
 +    Dim point As IOnPoint = objref.Point()
 +    If (point IsNot Nothing) Then
 +      RhUtil.RhinoApp.Print(String.Format("​Point:​ {0},​{1},​{2}"​ + vbCrLf,_
 +                                          point.point.x,​_
 +                                          point.point.y,​_
 +                                          point.point.z))
 +    End If
 +  End If
 +
 +  res = go.GetObjects(1,​ 0)
 +  If (res = IRhinoGet.result.object) Then
 +    For i As Integer = 0 To go.ObjectCount() - 1
 +      Dim objref As IRhinoObjRef = go.Object(i)
 +      Dim point As IOnPoint = objref.Point()
 +      If (point IsNot Nothing) Then
 +        RhUtil.RhinoApp.Print(String.Format("​Point {3}: {0},​{1},​{2}"​ + vbCrLf,_
 +                                            point.point.x,​_
 +                                            point.point.y,​_
 +                                            point.point.z,​ i))
 +      End If
 +    Next i
 +  End If
 +
 +  Return IRhinoCommand.result.success
 +End Function
 +</​code>​
 +===== C# =====
 +<code c#>
 +public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
 +{
 +   ​MRhinoGetObject go = new MRhinoGetObject();​
 +   ​go.SetCommandPrompt("​Select Point"​);​
 +   ​go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.point_object);​
 +   ​IRhinoGet.result res = go.GetObjects(1,​0);​
 +   if (res == IRhinoGet.result.@object)
 +   {
 +     for (int i = 0; i < go.ObjectCount();​ i++)
 +     {
 +       ​IRhinoObjRef objref = go.Object(i);​
 +       ​IOnPoint point = objref.Point();​
 +       if (point != null)
 +       {
 +         ​RhUtil.RhinoApp().Print(string.Format("​Point {3}: {0},{1},{2} \n",
 +                                               ​point.point.x,​
 +                                               ​point.point.y,​
 +                                               ​point.point.z,​ i));
 +       }
 +     }
 +   }
 +   ​return IRhinoCommand.result.success;​
 +}
 +
 +</​code>​
 +
 +
 +{{tag>​Developer cplusplus dotnet}}
  
developer/sdksamples/pickpoint.txt ยท Last modified: 2015/09/14 (external edit)