Site Tools


Differences

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

Link to this comparison view

developer:rhinocommonsamples:addobjectstogroup [2015/09/14] (current)
Line 1: Line 1:
 +===== Sample: Add Objects to Group =====
 +
 +===== C# =====
 +<code c#>
 +public static Rhino.Commands.Result AddObjectsToGroup(Rhino.RhinoDoc doc)
 +{
 +  Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();​
 +  go.SetCommandPrompt("​Select objects to group"​);​
 +  go.GroupSelect = true;
 +  go.GetMultiple(1,​ 0);
 +  if (go.CommandResult() != Rhino.Commands.Result.Success)
 +    return go.CommandResult();​
 +
 +  List<​Guid>​ ids = new List<​Guid>​();​
 +  for (int i = 0; i < go.ObjectCount;​ i++)
 +  {
 +    ids.Add(go.Object(i).ObjectId);​
 +  }
 +  int index = doc.Groups.Add(ids);​
 +  doc.Views.Redraw();​
 +  if (index >= 0)
 +    return Rhino.Commands.Result.Success;​
 +  return Rhino.Commands.Result.Failure;​
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Shared Function AddObjectsToGroup(ByVal doc As Rhino.RhinoDoc) As Rhino.Commands.Result
 +  Dim go As New Rhino.Input.Custom.GetObject()
 +  go.SetCommandPrompt("​Select objects to group"​)
 +  go.GroupSelect = True
 +  go.GetMultiple(1,​ 0)
 +  If go.CommandResult() <> Rhino.Commands.Result.Success Then
 +    Return go.CommandResult()
 +  End If
 +
 +  Dim ids As New List(Of Guid)()
 +  For i As Integer = 0 To go.ObjectCount - 1
 +    ids.Add(go.[Object](i).ObjectId)
 +  Next
 +  Dim index As Integer = doc.Groups.Add(ids)
 +  doc.Views.Redraw()
 +  If index >= 0 Then
 +    Return Rhino.Commands.Result.Success
 +  End If
 +  Return Rhino.Commands.Result.Failure
 +End Function
 +</​code>​
 +===== Python =====
 +<code python>
 +import Rhino
 +import scriptcontext
 +
 +def AddObjectsToGroup():​
 +    go = Rhino.Input.Custom.GetObject()
 +    go.SetCommandPrompt("​Select objects to group"​)
 +    go.GroupSelect = True
 +    go.GetMultiple(1,​ 0)
 +    if go.CommandResult()!=Rhino.Commands.Result.Success:​
 +        return go.CommandResult()
 +    ​
 +    ids = [go.Object(i).ObjectId for i in range(go.ObjectCount)]
 +    index = scriptcontext.doc.Groups.Add(ids)
 +    scriptcontext.doc.Views.Redraw()
 +    if index>​=0:​ return Rhino.Commands.Result.Success
 +    return Rhino.Commands.Result.Failure
 +
 +
 +if __name__ == "​__main__":​
 +    AddObjectsToGroup()
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
  
developer/rhinocommonsamples/addobjectstogroup.txt ยท Last modified: 2015/09/14 (external edit)