| McNeel Wiki | |||||
| edit · print · help · all topics | |||||
Main Pages
Languages
| The CRhinoGetObject SDK class is useful when you need the user to interactively pick one or more objects. But, it is not too useful if you need to walk through the entire document looking for objects. This is where the CRhinoObjectIterator SDK class comes in. The CRhinoObjectIterator class is used to iterate through the objects in a CRhinoDoc object. You can limit the iteration by specifying one of five mutually exclusive object states and one of three mutually exclusive object categories. The following is an example of using a CRhinoObjectIterator to select all objects. This example looks for all object that have not been deleted, and the objects can be in either the active document or in any referenced documents. C++
CRhinoCommand::result CCommandTestIterator::RunCommand(
const CRhinoCommandContext& context )
{
CRhinoObjectIterator it(
CRhinoObjectIterator::undeleted_objects,
CRhinoObjectIterator::active_and_reference_objects
);
it.IncludeLights( TRUE );
it.IncludeGrips( false );
int count = 0;
for( CRhinoObject* pObject = it.First(); pObject; pObject = it.Next() )
{
if( pObject->IsSelected() )
continue;
if( !pObject->IsSelectable() )
continue;
pObject->Select();
count++;
}
if( count )
context.m_doc.Redraw();
::RhinoApp().Print( L"%d object(s) selected.\n", count );
return CRhinoCommand::success;
}
For more information, see the rhinoSdkDoc.h SDK header file. VB.NET (Rhino 4)
Public Overrides Function RunCommand(ByVal context As IRhinoCommandContext) _
As IRhinoCommand.result
Dim it As New MRhinoObjectIterator( _
IRhinoObjectIterator.object_state.undeleted_objects, _
IRhinoObjectIterator.object_category.active_and_reference_objects)
it.IncludeLights(True)
it.IncludeGrips(False)
Dim count As Integer = 0
For Each pObject As MRhinoObject In it
If (pObject.IsSelected() > 0 Or Not pObject.IsSelectable()) Then
Continue For
End If
pObject.Select()
count = count + 1
Next
If (count > 0) Then context.m_doc.Redraw()
RhUtil.RhinoApp().Print(String.Format("{0} object(s) selected" + vbCrLf, count))
Return IRhinoCommand.result.success
End Function
C# (Rhino 4)
public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
{
MRhinoObjectIterator it = new MRhinoObjectIterator(
IRhinoObjectIterator.object_state.undeleted_objects,
IRhinoObjectIterator.object_category.active_and_reference_objects);
it.IncludeLights(true);
it.IncludeGrips(false);
int count = 0;
for (MRhinoObject pObject = it.First(); pObject != null; pObject = it.Next())
{
if (pObject.IsSelected() > 0)
continue;
if (!pObject.IsSelectable())
continue;
pObject.Select();
count++;
}
if (count > 0)
RhUtil.RhinoApp().ActiveDoc().Redraw();
RhUtil.RhinoApp().Print(string.Format("{0} object(s) selected\n", count));
return IRhinoCommand.result.success;
}
| ||||
| rename · changes · history · subscriptions · lost and found · references · file upload | |||||