How can I group existing objects in rhino using rhinocommon?

Hi,

I have bunch of rhino objects:
List<Rhino.DocObjects.RhinoObject> o … retrieved from rhino in C#

I am searching for method to make a groups out of list of rhino objects.

You need to add their id’s to the group table, which can be found as a property on the document, doc.Groups

http://developer.rhino3d.com/api/RhinoCommonWin/html/T_Rhino_DocObjects_Tables_GroupTable.htm

Yes, as menno said.
From the group table you can add an empty group and then add the objects to the latter.

Would it be possible to get very basic example?

http://developer.rhino3d.com/samples/rhinocommon/add-objects-to-group/

(From http://developer.rhino3d.com/samples/ )

2 Likes

Thank you:)

I solved it and your example saved me:

    protected override void SolveInstance(IGH_DataAccess DA)
    {
        GH_Structure<GH_Guid> tree;
        DA.GetDataTree(0, out tree);

        List<Guid> G = new List<Guid>();
        foreach (GH_Guid goo in tree.AllData(true))
            G.Add(goo.Value);

        int N = 2;
        DA.GetData(1, ref N);
        bool flag = false;
        DA.GetData(2, ref flag);

        if (flag)
        {
            if (N > 0 && N < G.Count)
            {
                G.Shuffle();
                var partitions = G.PartitionByN(N);

                for (int i = 0; i < partitions.Count(); i++)
                {

                    int index = Rhino.RhinoDoc.ActiveDoc.Groups.Add(partitions.ElementAt(i));
                    if (index >= 0)
                        base.Message = "Success";
                    else
                        base.Message = "Error";
                }
            }

}

1 Like