Sdk Pick Point
Last changed: -204.177.179.108

.
DeveloperC++, .NET
SummaryDemonstrates how to use CRhinoGetObject to pick point objects.

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++

For example, the following is how you could you pick a single point object:

  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);
  }

If you needed access to the CRhinoPointObject object, you could do this:

  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);
    }
  }

Here is how you can pick one or more point objects:

  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 );
    }
  }

VB.NET (Rhino 4)

  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

C# (Rhino 4)

  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;
  }