Create planar Brep via Rhino3dm NET

Dear McNeel,

Is it possible to create a planar Brep with a hole, via Rhino3dm NET library?
Like so:

I tried creating a planar Brep, without the hole, and a resulting brep is Valid.
However, when I add the hole crv, the rg.Brep.CreateTrimmedPlane method creates invalid Brep.

I would be very grateful for any kind of help on this issue.
This is the the example:

# a) create outer and inner (hole) rectangles
vecUp = rg.Vector3d(0,0,1)

pln1 = rg.Plane(rg.Point3d(0,0,0), vecUp)
pln2 = rg.Plane(rg.Point3d(600,400,0), vecUp)

outer_rect = rg.Rectangle3d(pln1, rg.Interval(0,2000), rg.Interval(0,1200))
hole_rect = rg.Rectangle3d(pln2, rg.Interval(0,800), rg.Interval(0,400))

outer_rect_crv = outer_rect.ToNurbsCurve()
hole_rect_crv = hole_rect.ToNurbsCurve()

#outer_inner_crv_L = [outer_rect_crv]  # WORKS! Creates a valid Brep
outer_inner_crv_L = [outer_rect_crv, hole_rect_crv]  # does not work. Creates invalid Brep.



# b) create a brep from rectangles
brep = rg.Brep.CreateTrimmedPlane(pln1, outer_inner_crv_L)
print 'brep: ', brep.IsValid

I’m no expert on this by any means, but the documentation states that the curves given should form one closed curve. But they don’t, because they are two curves.

Instead you probably want to use static Brep[] Brep.CreatePlanarBreps(IEnumerable<Curve> inputLoops, Double tolerance).

1 Like

Hi @nathanletwory ,

Thank you very much for the help!

Sadly Brep.CreatePlanarBreps method does not exist in rhino3dm.

This worked though: brep.Loops.AddPlanarFaceLoop

But you helped me by providing the link to the Brep.CreateTrimmedPlane method, which made me realize that it accepts only outer curves, and not inner ones.

Thank you for your effort, and willingness to always help!

1 Like

Ah right, I started looking into that, but then somehow completely forgot you were talking rhino3dm. Sorry about that!

But good that you found a solution!

Maybe for posterity post the code that does work for you with rhino3dm

1 Like

Hi @nathanletwory ,

No problem at all. You helped with the CreateTrimmedPlane link.

This is the working code:

# a) create outer and inner (hole) rectangles
vecUp = rg.Vector3d(0,0,1)

pln1 = rg.Plane(rg.Point3d(0,0,0), vecUp)
pln2 = rg.Plane(rg.Point3d(600,400,0), vecUp)

outer_rect = rg.Rectangle3d(pln1, rg.Interval(0,2000), rg.Interval(0,1200))
hole_rect = rg.Rectangle3d(pln2, rg.Interval(0,800), rg.Interval(0,400))

outer_rect_crv = outer_rect.ToNurbsCurve()
hole_rect_crv = hole_rect.ToNurbsCurve()

outer_crv_L = [outer_rect_crv] 
inner_crv_L = [hole_rect_crv]

# b) create a brep from rectangles
brep = rg.Brep.CreateTrimmedPlane(pln1, outer_crv_L)
brep.Loops.AddPlanarFaceLoop(0, rg.BrepLoopType.Inner, inner_crv_L)

print 'brep: ', brep.IsValid
2 Likes