[Bug?] Box.ToBrep() return Null

Of both Box and BoundingBox, To.Brep() method always return null.
Is this a bug or I misunderstanding the use? I want to get brep face from Box.
[bug] Box.ToBrep() return null.gh (6.0 KB)

This is probably due to the fact that your bounding box is a Flat Box, and thus invalid for a ToBrep() casting?

Screenshot 2021-07-22 at 08.01.15

Here’s how you can do this:

BoundingBox bbox = x.BoundingBox;
Point3d[] corners = bbox.GetCorners();

// Get the face boundary polyline
var faceCorners = new ArraySegment<Point3d>(corners, 0, 4);
Polyline pline = new Polyline(faceCorners);

// Get the face as Nurbs surface
Point3d c1 = corners[0]; 
Point3d c2 = corners[1];
Point3d c3 = corners[2];
Point3d c4 = corners[3];

NurbsSurface srf = NurbsSurface.CreateFromCorners(c1, c2, c3, c4);


// Outputs
A = pline;
B = srf;

I’m not a C# cowboy, so take this all with a grain of salt, but it seems to work. :yum:

[bug] Box.ToBrep() return null V2.gh (4.2 KB)

1 Like

Thank you. You have the point. Flat box is the problem.
Here is my version with fewer lines:

Box box = new Box(bbox);
var rectangle = new Rectangle3d(box.Plane, box.X, box.Y);
var face = Brep.CreatePlanarBreps(retangle.ToNurbsCurve(), tolerance)[0].Faces[0];