Getting the size of a rotated box/surface

Hi all, I’m sure others have done this.

I want to Python script getting the size of these boxes. If they were always rotated to 0, 90, 180 & 270 it wouldn’t be an issue using BoundingBox, but as they could be at an angle the BoundingBox doesn’t give useful information. (refer attached)

They height is easy, as that will be the difference between Zmax and Zmin in a BoundingBox, but I don’t know how to get the other sizes. Is there a BoundingBox that will fit snugly around the object so I can have it’s height, width and depth?

Thanks

Adrian

Hi Adrian,

I’m not at my computer at the moment, but I think you should be able to set a cplane to the object, use bounding box to get your dimensions with cplane coordinates, then revert to the previous cplane.

HTH
Jeremy

If it’s always a rectilinear box object, you can deconstruct it in the script and get the dimensions of the sides, so that’s not too hard. However if it’s not, then you would need an iterative minimum bounding box finder - there are some scripts floating around out there plus some GH definitions.

Thanks @jeremy5,

I gave that a try, but unfortunately the user needs to pick a face on the surface, it won’t align to the surface itself, so the approach wouldn’t allow me to loop through a selection of surfaces. Unless I’ve misunderstood your suggestion.

Sample below

Adrian

import rhinoscriptsyntax as rs
def align_cplane():
    obj = rs.GetObject("Pick object")
    rs.Command("-CPlane Object SelID "+str(obj)+" Enter ")

align_cplane()

Thanks @Helvetosaur,

By ‘Deconstruct’ do you mean explode it, then loop through the parts? That could work.
Or is there a way to sift through the individual faces/sides without exploding?

Cheers,

Adrian

In RhinoScript there are methods: IsBox and BoxPoints which are missing from RhinoScript syntax, but you may try to find equivalents in RhinoCommon:
Brep.IsBox Method (rhino3d.com)
I can’t find quivalent of BoxPoints method… if we could find that then you can get ordered box points from your Brep to measure X,Y,Z size of your box no matter the orientation.

Is Minbox still a thing? There used to be a free plugin for R5 called Minbox that was made for this very thing.

Thanks @Jarek, Yes BoxPoints would be perfect, it is a shame that isn’t available in Python. I haven’t yet ventured into RhinoCommon, but it is looking like something I’ll need to get into and learn.
Cheers,
Adrian

Have a look at this:

import Rhino

def getFaceInfo():
    filter = Rhino.DocObjects.ObjectType.Brep
    rc, objref = Rhino.Input.RhinoGet.GetOneObject("Select brep", False, filter)
    if not objref or rc!=Rhino.Commands.Result.Success: return rc

    brep = objref.Brep()
    if not brep:
        return Rhino.Commands.Result.Failure

    for face in brep.Faces:
        faceBrep = face.ToBrep()
        print "Face[{}] Area: {}".format(face.FaceIndex, faceBrep.GetArea())
        for edge in faceBrep.Edges:
            print "Edge[{}] Length: {}".format(edge.EdgeIndex, edge.GetLength())
        for vert in faceBrep.Vertices:
            print "Vertice[{}]: {}".format(vert.VertexIndex, vert.Location)
        print

if __name__=="__main__":
    getFaceInfo()

getFaceInfo.py (742 Bytes)

-Kevin

1 Like

Wow, yes @kev.r that definitely digs out all of the details I’m after!
I can see I need to get myself into RhinoCommon!
Thank you,
Adrian

Yes, looks like @kev.r already has you covered there.