Ghpython Bounding box rotate

I need to create a bounding box for a polysurface. I can use grasshopper to make the rotated bounding box. However, I need to add it to my GHpython script. Is there any way I can rotated the bounding box just as my grasshopper component? My expectation should be like the sketch in the image.


BoundingBox.gh (7.0 KB)

Welcome @liunuozhi1995,

This should work, when the type hints of both inputs x and y are set to No Type Hint:

2 Likes

In addition to @diff-arch’s great reply (that uses RhinoCommon), you can also compute an oriented BoundingBox with RhinoScript. As an additional bonus, RhinoScript bounding boxes can be tapered later, because they are simple lists of 8 corner points.

To make this work easily, I set the Type Hint of the P input as “Plane”.

1 Like

@diff-arch @piac Thank you all kindly help. Just wonder, is there any possible to extract the plane from the brep directly inside GHpython instead of adding new input?

@liunuozhi1995, I also asked myself that yesterday, but wasn’t able to come up with an adequate solution.
Maybe @Dancergraham, @ivelin.peychev, @AndersDeleuran, or some other GHPython aficionado can help here?

If you want to get the exact same Plane you can use GH_Convert.ToPlane like this:

import Grasshopper
import Rhino.Geometry as rg
plane = Grasshopper.Kernel.GH_Convert.ToPlane(x, rg.Plane.Unset, Grasshopper.Kernel.GH_Conversion.Both)[1]
bbox = rg.Box(plane, x.GetBoundingBox(plane))

Ronn.gh (14.0 KB)

2 Likes

I might not have understood the problem, but you can cast a BoundingBox to a Box (using this constructor) and then get its plane (through this property).

1 Like

Hi,

This is the best solution I can suggest to you.

Thank @Helvetosaur for his great work.

2 Likes