I’m trying to access the Rhino.Geometry.Box.Z method to give the Z height of a bounding box, but can’t get a handle on the syntax for using Rhino Common functions with Python. Can anyone explain? preferably with an example.
Hi Adam,
Not a true answer but to get the max Z of a Boundingbox as returned by rhinoscriptsyntax try this:
import rhinoscriptsyntax as rs
def Main():
obj_id = rs.GetObject('getobject for boundingbox')
if not obj_id: return
bbox = rs.BoundingBox(obj_id)
#get Z value of the bbox first upper corner
print bbox[4].Z
Main()
Does that help?
-WIllem
Yes, perfect, I’m still curious about how I can use rhinocommon methods with python, but this does what i’m after.
In Grasshopper this works:
"""
- I have a box connected to a Python component
- The input is called 'Box'
- Type hint is 'Box'
"""
print(Box.BoundingBox.Max.Z)
Here is another mix of rhinoscriptsyntax (just to select the object) and RhinoCommon…
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
def TestGetBB():
objID=rs.GetObject("Select object for bounding box",preselect=True)
if not objID: return
obj=sc.doc.Objects.Find(objID).Geometry
bb=obj.GetBoundingBox(False)
if bb: print "Bounding box max Z is {}".format(bb.Max.Z)
TestGetBB()
1 Like
interesting. Can you point me to any good resources for understanding the rhino common syntax in rhino.python? the googles is kind of failing me on this one.