How to get a Block size?

Dear all,

I got a Block which type is instance reference. How I can get the size from this type? I know maybe the size needs calculate the xform or R0,R1 ,R2 and R3. May anybody can tell me how to do it? thanks very very much.

import Rhino

def getBoundingBox():
    filter = Rhino.DocObjects.ObjectType.AnyObject
    rc, objref = Rhino.Input.RhinoGet.GetOneObject("", False, filter)
    if not objref or rc != Rhino.Commands.Result.Success: 
        return
    print objref.Object().Geometry.GetBoundingBox(Rhino.Geometry.Plane.WorldXY)
getBoundingBox()

Thanks for the help Gijs, there is a problem with the plane. when the plane is woldXY, it’s a right result but when the Block turns to 10°, the bounding box gets a wrong result. It should be like the red rectangle. Could U tell me how to get the plane of Block or xform ?
sss

Hi,

Bounding boxes are axis aligned. Even when transformed they’ll stay axis aligned and wrap the transformed box.

https://developer.rhino3d.com/api/cpp/class_o_n___bounding_box.html#a6308e193f97335a85cb6dd91f4645825

Blocks of course have their instance xform.

https://developer.rhino3d.com/api/RhinoCommon/html/P_Rhino_Geometry_InstanceReferenceGeometry_Xform.htm

One thing you can do is get the original geometries bounding boxes corners and transform those points individually. This will give you a transformed box that isn’t world aligned. You may also find the Box structure useful.

https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Geometry_Box.htm

I do something similar-ish in Bongo. This won’t be much help though if your original geometry isn’t created with axis alignment in mind.

What do you need this box for? Maybe if you let us know the broader problem you’re trying to solve we can give you a better answer.

Thank you Joshua,I just want to get the real size from a block object. Could you give me some suggestion ?

Dear all, I just get xform from InstanceXform,How Can I get the scale,rotation info from InstanceXform?

how about this:

import Rhino

def getBoundingBox():
    filter = Rhino.DocObjects.ObjectType.AnyObject
    rc, objref = Rhino.Input.RhinoGet.GetOneObject("", False, filter)
    if not objref or rc != Rhino.Commands.Result.Success: 
        return
    X = objref.Object().Geometry.Xform
    plane = Rhino.Geometry.Plane.WorldXY
    plane.Transform(X)
    print objref.Object().Geometry.GetBoundingBox(plane)
getBoundingBox()

Hi Gijs, it doesn’t work, I think I have to explore the mesh from the block then calculate the size :joy: Thank you for help!