I currently don’t understand on how to get the 3D Bounding Box of a component.
I’m sorry for asking so much.
import rhinoscriptsyntax as rs
import ghpythonlib as ghpy
import Grasshopper as gh
pt = rs.CreatePoint(0,0,0)
box = ghpy.components.BoundingBox(mesh,ghpy.components.XYPlane(pt))
#print(dir(box)) # <-- Is this a bug?
Runtime error (TypeErrorException): unsupported operand type(s) for +: 'list' and 'Array[str]'
line 81, in __dir__, "\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\ghpythonlib\components.py"
line 14, in script
# These all return Rhino.Geometry.Box, even when using nonsense attributes like in the last line.
No problem in asking too much, that’s what this forum is for.
I changed this to grashopper category because you are using gh components. There you will have better chances of getting usefull help. Also try to attach en example gh file for easier reproduction of the issue.
import Rhino.Geometry as rg
pt = rg.Point3d(0, 0, 0) # or rg.Point2d.Origin (also creates a point at the origin)
bbox = mesh.GetBoundingBox(False) # or mesh.GetBoundingBox(True) for physical accuracy but slower
print bbox.Volume, bbox.MinimumCoordinate, bbox.MaximumCoordinate
I recon mesh refers to a component input? If so, you probably need to set its type hint to mesh!
Here are some links to the relevant reference pages, if you for instance want to look up some methods and/or attributes of the BoundingBox structure:
A structure, much like a class, is a data structure, a way to structure your code. In C# structures are stack allocated, which brings some performance benefits, compared to classes, which are all reference types and heap allocated. Heap allocated symbols need to be cleaned up when they run out of scope or are not needed anymore, and that’s were the garbage collector comes in. If you allocated lots of objects in heap memory, the garbage collector probably also has a lot of work to do and this entails a performance penalty, but that’s an other story really.
Honestly, I’d forget about node in code. Theoretically, it’s a nice concept, but also pretty much redundant. Use rhinoscriptsyntax or even better the API (aka RhinoCommon), like I do above.
If you have questions, just ask here or in the Scripting forum!