How to get a bounding box for whole group?

#x is a group of bounding Breps
BB = x.GetBoundingBox(Rhino.Geometry.Plane.WorldXY) #works for one object but doesn’t for a group of objects

#Python #BoundingBox #grasshopper #scripting #group

import Rhino.Geometry as rg
bbox = rg.BoundingBox.Empty
for brep in breps:
    bbox.Union(brep.GetBoundingBox(rg.Plane.WorldXY))
a = bbox

bbox.gh (118.3 KB)

1 Like

@Mahdiyar
Done! Thank you! Could you clarify a moment, what is really this Empty? Is it like Empty Box required for the Union method?

Exactly.

@Mahdiyar
Thanks

Not required for Union; you can perfectly fine Union one non empty bbox with another.

Yet in this case you need an initial boundingbox to union your first object bbox with.
That initial Empty bbox is the seeding container for the first bbox.

Without an Empty bbox, you could also have done this:

import Rhino.Geometry as rg
bbox = None
for brep in breps:
    if bbox is None:
        bbox = brep.GetBoundingBox(rg.Plane.WorldXY)
    else:
        bbox.Union(brep.GetBoundingBox(rg.Plane.WorldXY))
a = bbox

-Willem

1 Like

@Willem
Big thanks for your clarification!

1 Like