The Rhino SDK provides the class CRhinoGetObject (MRhinoGetObject in Rhino.NET), that will allow you to interactively select objects on the screen. This is a large class with a number of options. It is recommended that you read through the header file, rhinoSdkGetObject.h, before using.
To use the CRhinoGetObject class, simply put one on the stack and call it's GetObjects() member. It is possible to derive custom classes from CRhinoGetObject . But, the class is powerful enough that deriving new class from it is usually unnecessary.
If an instance of CRhinoGetObject was successful in selecting one or more objects, then use it's Object() member to retrieve information about the object that was selected. The Object() member returns a CRhinoObjRef class which has a number of member functions to help you quickly get to the information you are looking for.
C++
CRhinoGetObject go;
go.SetCommandPrompt( L"Select object" );
CRhinoGet::result res = go.GetObjects( 1, 1 );
if( res == CRhinoGet::object )
{
const CRhinoObjRef& obj_ref = go.Object( 0 );
const CRhinoObject* obj = obj_ref.Object();
if( obj )
{
// TODO
}
}
VB.NET (Rhino 4)
Dim go As New MRhinoGetObject()
go.SetCommandPrompt("Select object")
Dim res As IRhinoGet.result = go.GetObjects(1, 1)
If (res = IRhinoGet.result.object) Then
Dim obj_ref As MRhinoObjRef = go.Object(0)
Dim obj As IRhinoObject = obj_ref.Object()
If (obj IsNot Nothing) Then
' TODO
End If
End If
C++
CRhinoGetObject go;
go.SetCommandPrompt( L"Select objects" );
CRhinoGet::result res = go.GetObjects( 1, 0 );
if( res == CRhinoGet::object )
{
int i, count = go.ObjectCount();
for( i = 0; i < count; i++ )
{
const CRhinoObjRef& obj_ref = go.Object( 0 );
const CRhinoObject* obj = obj_ref.Object();
if( obj )
{
// TODO
}
}
}
VB.NET (Rhino 4)
Dim go As New MRhinoGetObject()
go.SetCommandPrompt("Select objects")
Dim res As IRhinoGet.result = go.GetObjects(1, 0)
If (res = IRhinoGet.result.object) Then
Dim count As Integer = go.ObjectCount()
For i As Integer = 0 To count - 1
Dim obj_ref As MRhinoObjRef = go.Object(i)
Dim obj As IRhinoObject = obj_ref.Object()
If (obj IsNot Nothing) Then
' TODO
End If
Next
End If
C++
CRhinoGetObject go;
go.SetCommandPrompt( L"Select curve" );
go.SetGeometryFilter( CRhinoGetObject::curve_object );
CRhinoGet::result res = go.GetObjects( 1, 1 );
if( res == CRhinoGet::object )
{
const CRhinoObjRef& obj_ref = go.Object( 0 );
const ON_Curve* crv = obj_ref.Curve();
if( crv )
{
// TODO
}
}
VB.NET (Rhino 4)
Dim go As New MRhinoGetObject()
go.SetCommandPrompt("Select curve")
go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object)
Dim res As IRhinoGet.result = go.GetObjects(1, 1)
If (res = IRhinoGet.result.object) Then
Dim obj_ref As MRhinoObjRef = go.Object(0)
Dim crv As IOnCurve = obj_ref.Curve()
If (crv IsNot Nothing) Then
' TODO
End If
End If