Two overloads here:
If I just use obj.GetBoundingBox(plane)
, it uses the second overload, and I get the box output in plane coordinates. I would like the first, the plane-oriented bounding box, but in world coordinates… How to?
Two overloads here:
If I just use obj.GetBoundingBox(plane)
, it uses the second overload, and I get the box output in plane coordinates. I would like the first, the plane-oriented bounding box, but in world coordinates… How to?
Hi Mitch,
I used your script to move objects to origin, it works great! Do you know of any scripts for automating the Make2D to generate Section Views?
Hi Dale,
I don’t do C# - but… I see you first need to get the transform (xform) from World XY to the desired plane, then use GetBoundingBox(xform), then transform the results back from the plane to World XY …
I don’t understand why there isn’t an overload in the method to do the above forward/reverse transform automatically? It would seem this would be a pretty common thing to want - the plane oriented bounding box but with the results in world coordinates.
Hi Mitch,
Does this do what you’re looking for?
import rhinoscriptsyntax as rs
from scriptcontext import doc
from Rhino.Geometry import Plane, Box
import clr
oBox = clr.Reference[Box]()
b = SomeBrep()
p = SomePlane()
bb = b.GetBoundingBox(p, oBox)
box = oBox.Value
doc.Objects.AddBox(box)
rs.Redraw()
Hi Alain,
Thanks for the sample, no, it doesn’t unfortunately. While it shows me the way to use the overload, I guess I misunderstood what that overload outputs… It’s not what I expected.
In the file below, there is an off-axis rectangle and I want to get the center of its bounding box relative to the curve plane and add a point there (the point in the file is the plane-aligned bb center, locked for reference).
TestBBRect.3dm (2.2 MB)
This does not work:
import rhinoscriptsyntax as rs
import Rhino, clr
def TestPlaneOrientedBB():
obj_id=rs.GetObject("Pick rectangle",4,preselect=True)
if obj_id:
crv=rs.coercecurve(obj_id)
rc,plane=crv.TryGetPlane()
if rc:
wxy=Rhino.Geometry.Plane.WorldXY
plane.Origin=crv.PointAtStart
oBox = clr.Reference[Rhino.Geometry.Box]()
bb=crv.GetBoundingBox(plane,oBox)
rs.AddPoint(bb.Center)
TestPlaneOrientedBB()
This does (forward/reverse transformation):
import rhinoscriptsyntax as rs
import Rhino
def TestPlaneOrientedBB():
obj_id=rs.GetObject("Pick rectangle",4,preselect=True)
if obj_id:
crv=rs.coercecurve(obj_id)
rc,plane=crv.TryGetPlane()
if rc:
wxy=Rhino.Geometry.Plane.WorldXY
plane.Origin=crv.PointAtStart
out_xform=Rhino.Geometry.Transform.ChangeBasis(wxy,plane)
bb=crv.GetBoundingBox(out_xform)
#rs.AddPoint(bb.Center)
in_xform=Rhino.Geometry.Transform.ChangeBasis(plane,wxy)
new_pt=rs.PointTransform(bb.Center,in_xform)
rs.AddPoint(new_pt)
TestPlaneOrientedBB()
@Helvetosaur is looking for the RhinoCommon equivalent of this:
https://developer.rhino3d.com/api/rhinoscript/geometry_methods/boundingbox.htm
– Dale
Yes, finally I just made my own function:
def GetPlaneAlignedBBCtr(obj,plane):
wxy=Rhino.Geometry.Plane.WorldXY
out_xform=Rhino.Geometry.Transform.ChangeBasis(wxy,plane)
bb=obj.GetBoundingBox(out_xform)
if bb:
in_xform=Rhino.Geometry.Transform.ChangeBasis(plane,wxy)
return in_xform*bb.Center