Sdk Add Objects To Group
Last changed: stevebaer-204.177.179.109

.
DeveloperC++, .NET
SummaryDemonstrates how to add selected objects to an object group.

The following code sample demonstrates how to add selected objects to an object group using the Rhino SDK.

C++

  CRhinoCommand::result CCommandTestSdk::RunCommand(const CRhinoCommandContext& context)
  {
    CRhinoGetObject go;
    go.SetCommandPrompt( L"Select objects to group" );
    go.EnableGroupSelect();
    go.GetObjects(1,0);
    if( go.CommandResult() != CRhinoCommand::success )
      return go.CommandResult();


    int i = 0, count = go.ObjectCount();
    ON_SimpleArray<const CRhinoObject*> members( count );


    for( i = 0; i < count; i++ )
      members.Append( go.Object(i).Object() );


    int index = context.m_doc.m_group_table.AddGroup( ON_Group(), members );
    context.m_doc.Redraw();
    return (index >= 0) ? CRhinoCommand::success : CRhinoCommand::failure;
  }

VB.NET (Rhino 4)

  Public Overrides Function RunCommand(ByVal context As IRhinoCommandContext) _
    As IRhinoCommand.result


    Dim go As New MRhinoGetObject()
    go.SetCommandPrompt("Select objects to group")
    go.EnableGroupSelect()
    go.GetObjects(1, 0)
    If (go.CommandResult() <> IRhinoCommand.result.success) Then Return go.CommandResult()


    Dim count As Integer = go.ObjectCount()
    Dim members As New System.Collections.Generic.List(Of IRhinoObject)(count)
    For i As Integer = 0 To count - 1
      members.Add(go.Object(i).Object())
    Next


    Dim member_array() As IRhinoObject = members.ToArray()
    Dim index As Integer = context.m_doc.m_group_table.AddGroup(New OnGroup(), member_array)
    context.m_doc.Redraw()


    If (index >= 0) Then Return IRhinoCommand.result.success
    Return IRhinoCommand.result.failure
  End Function

C# (Rhino 4)

  public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
  {
    MRhinoGetObject go = new MRhinoGetObject();
    go.SetCommandPrompt("Select objects to group");
    go.EnableGroupSelect();
    go.GetObjects(1, 0);
    if( go.CommandResult() != IRhinoCommand.result.success )
      return go.CommandResult();


    int count = go.ObjectCount();
    System.Collections.Generic.List<IRhinoObject> members =
      new System.Collections.Generic.List<IRhinoObject>(count);
    for( int i=0; i<count; i++)
      members.Add(go.Object(i).Object());


    IRhinoObject[] member_array = members.ToArray();
    int index = context.m_doc.m_group_table.AddGroup(new OnGroup(), member_array);
    context.m_doc.Redraw();


    if(index >= 0)
      return IRhinoCommand.result.success;
    return IRhinoCommand.result.failure;
  }