A bounding box in various objects

Hi friends
I selected several objects on the screen, however need to create a single bounding box around all objects, so I can move them to another point. It would be possible to post an example in C # that make this function.

Thanks

Calculate the bounding box of each object and then union the bounding boxes (together) using Rhino.Geometry.BoundingBox.Union. Does this help?

Below is the code what Iā€™m trying to do, the problem is that central point is not generated from the bounding box that encompasses all objects.

        var go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select objects");
        go.EnablePreSelect(true, true);
        go.EnablePostSelect(true);
        go.GetMultiple(0, 0);

        if (go.CommandResult() != Result.Success)
        {
            return go.CommandResult();
        }
        Point3d pt = new Point3d(0, 0, 0);
        var bBox = new BoundingBox();

        var selected_objects = go.Objects().ToList();
        foreach (var obj in go.Objects())
        {
            bBox = obj.Geometry().GetBoundingBox(true);
            bBox.Union(pt);
        }
        doc.Objects.AddPoint(bBox.Center);
        doc.Views.Redraw();
        return Result.Success;

What you want to do is this

var go = new Rhino.Input.Custom.GetObject();
go.SetCommandPrompt("Select objects");
go.EnablePreSelect(true, true);
go.EnablePostSelect(true);
go.GetMultiple(0, 0);

if (go.CommandResult() != Result.Success)
{
    return go.CommandResult();
}

BoundingBox bBox = BoundingBox.Unset;

var selected_objects = go.Objects().ToList();
foreach (var obj in go.Objects())
{
    BoundingBox bbObj = obj.Geometry().GetBoundingBox(true);
    bBox.Union(bbObj); // union the object bounding box with the overall bounding box
}
doc.Objects.AddBrep(bBox.ToBrep()); // see the box
doc.Objects.AddPoint(bBox.Center); // see the center
doc.Views.Redraw();
return Result.Success;
1 Like

100% Functional.
Thank you all