Splitting a brep face with curves using BrepFace.Split Method

Maybe I’m using this wrong, but I can’t get it to work…

http://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_BrepFace_Split.htm

Says I can split a brep face with a collection of 3d curves… Doesn’t seem to work here, always errors out. You can see the state in the debugger below just before the line in question, ut_face is a brep face, bords is a list of Nurbs curves (splitters), tol is just a tolerance value…

What I get is this:
Message: iteration over non-sequence of type Brep

Looks like it’s expecting a Brep - also supported by this overloaded function. What do I have to do to get it to accept my curve list? Do I have to convert the list into an IEnumerable? (I’ve forgotten how one does that…)

Edit:
I tried using a generic .NET list as I saw in another discussion by adding the following:

from System.Collections.Generic import List
bords=List[Rhino.Geometry.Curve](bords)

But I still get the same error message…

Thanks, --Mitch

1 Like

Hi Mitch,

The BrepFace.Split method returns a single brep, not a list of breps. That’s causing your error.
That single brep (splits) has its faces splitted according to your cutting curves (bords).
So to get the breps out of all those splits brep faces, call the DuplicateFace method:

for brepFace in splits.Faces:
    brep = brepFace.DuplicateFace(False)

Ah, yes, stupid me - suspecting that, I had even put in a breakpoint to check what splits was, but it never got to the breakpoint, so I assumed it was erroring out on the Brep.Split function. In fact, it was skipping the breakpoint I put because it was at a for loop and just went to the next line… And the error message even said it was erroring out on the following line but I just spaced it…

Thanks Djordje! --Mitch

1 Like

OK, getting back to this… I am not getting it to work so far. SplitBrep() returns the appropriate number of parts, but all the parts are the same untrimmed, unsplit base surfaces… :confounded: What am I missing here…?

Thanks, --Mitch

Test code:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def TestBrepSplitCurve():
    srfID=rs.GetObject("Select surface to split",8)
    crvID=rs.GetObject("Select curve to split with",4)
    brep=sc.doc.Objects.Find(srfID).Geometry
    crv=sc.doc.Objects.Find(crvID).Geometry
    tol=sc.doc.ModelAbsoluteTolerance
    split_brep=brep.Faces[0].Split([crv],tol)
    rs.DeleteObjects([srfID,crvID])
    for face in split_brep.Faces:
        sc.doc.Objects.AddBrep(face.ToBrep())
    sc.doc.Views.Redraw()
TestBrepSplitCurve()

Test file:
BrepSplitEx.3dm (232.5 KB)

Hi Mitch,

You should have used the upper mentioned brepFace.DuplicateFace method:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def TestBrepSplitCurve():
    srfID=rs.GetObject("Select surface to split",8)
    crvID=rs.GetObject("Select curve to split with",4)
    brep=sc.doc.Objects.Find(srfID).Geometry
    crv=sc.doc.Objects.Find(crvID).Geometry
    tol=sc.doc.ModelAbsoluteTolerance
    split_brep=brep.Faces[0].Split([crv],tol)
    rs.DeleteObjects([srfID,crvID])
    for face in split_brep.Faces:
        sc.doc.Objects.AddBrep(face.DuplicateFace(False))
        #sc.doc.Objects.AddBrep(face.ToBrep())
    sc.doc.Views.Redraw()
TestBrepSplitCurve()

It creates a new brep from the brepFace.

Breps contain trimming information.
Surfaces do not. By using the surface.ToBrep method you essentially lost the trimming information.
This is why the resulting geometry is untrimmed.

OK, thanks, I was just assuming that face.ToBrep() would do the same as face.DuplicateFace() - but I see it doesn’t.

Cheers, --Mitch