X-axis auto rotate script

I have a script, attached, which I want to use for orienting curves or polysurfaces so that the longest edge of their bounding box is aligned to the X axis. It sort of works but I can’t a truly tight bounding box. The attached file shows the sort of curve I am trying to orient and the bounding box I am getting, along with the desired bounding box. Both bounding boxes are on their own layers. If I could get a truly tight bounding box for the object the rest of the script works as desired. Can anyone tell me what I’m doing wrong in calculating a tight bounding box?
orient_test.3dm (2.1 MB)
AlignLongestEdgeToXAxis.py (4.1 KB)

1 Like

A true minimum bounding box can only be calculated iteratively (to within a given tolerance) as far as I understand. There is a long-running thread in the Grasshopper section of the forum on this.

Below is an old, old script of mine for calculating a minimum XY-projected plane bounding rectangle - based on smallest rectangle area. One can also vary the criteria to evaluate to find the shortest side or something else. The second one below (more recent) works with planar objects in any plane and finds the box with the shortest side. The ideas could be extended to 3D objects.

XYMinBoundingRectangle.py (3.4 KB)
XYMinBoundingRectangle3.py (7.1 KB)

Edit - I hacked this together from my other script. It attempts to find the planar bounding box with the longest side for each of the selected planar objects selected. No idea if it works for you…

XYMaxSideBoundingRectangle.py (7.2 KB)

Thanks very much. I was able to incorporate it into my script. Works perfect.

I also need this script function, Looking forward to you sharing it after you improve it.

Here you go. I only use it for curves, so if you need 3D objects you’ll need to dig a little deeper.

(attachments)

AlignLongestEdgeToXAxis.py (8.77 KB)

1 Like