Type Conversion
In RhinoBommon API, you often need to convert between different types of geometric objects. This is because different operations are available for different types of objects.
For example, a Rhino.Geometry.Box
object represents a box in 3D space. It has properties like Plane
, X
, Y
, Z
that represent the orientation and dimensions of the box. However, it doesn’t have methods for more complex operations like boolean operations, offsetting, etc.
In order to have such operations, a box is needed to be converted to Rhino.Geometry.Brep
API Documentation for Box Struct
API Documentation for BREP Class
In the above images taken from the RhinoCommon Documentation we can see the different number of methods and propeties be accessed for each type
To convert a Rhino.Geometry.Box
to a Rhino.Geometry.Brep
, you can use the ToBrep
method of the Box class:
import Rhino.Geometry as rg
# Create a box
box = rg.Box(rg.Plane.WorldXY, rg.Interval(-1, 1), rg.Interval(-1, 1), rg.Interval(-1, 1))
# Convert the box to a brep
brep = box.ToBrep()