Odd results with Rhino.Geometry.Brep.CreateBooleanSplit()

For another thread, I was testing some sample code using RhinoCommon Brep.CreateBooleanSplit() and I ran into an oddity… It is creating a lot of empty split results and I can’t explain why. I am filtering those out currently, but it’s odd.

Test code

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def GetObjectsBoundingBox(objs):
    bbox=Rhino.Geometry.BoundingBox()
    for obj in objs:
        bb=obj.GetBoundingBox(True)
        bbox=Rhino.Geometry.BoundingBox.Union(bbox,bb)
    return bbox

def TestBoolSplit():
    obj_ids=rs.GetObjects("Select objects to split",8+16,preselect=True)
    if not obj_ids: return
    
    vert_space=10.0 #fixed value for testing
    tol=sc.doc.ModelAbsoluteTolerance
    objs=[rs.coercebrep(obj_id) for obj_id in obj_ids]
    bbx=GetObjectsBoundingBox(objs)
    #make the box a little bigger in X and Y
    bbx.Inflate(1.0,1.0,0)
    plane=Rhino.Geometry.Plane.WorldXY
    plane.Origin=bbx.Min
    x_interval=Rhino.Geometry.Interval(0,bbx.Diagonal.X)
    y_interval=Rhino.Geometry.Interval(0,bbx.Diagonal.Y)
    #make a plane surface at bottom of box
    plane_srf=Rhino.Geometry.PlaneSurface(plane,x_interval,y_interval).ToBrep()
    plane_count=int((bbx.Max.Z-bbx.Min.Z)/vert_space)
    move_vec=Rhino.Geometry.Vector3d(0,0,vert_space)
    print "Split plane interval count = {}".format(plane_count)
    
    #move plane up one vertical increment
    plane_srf.Translate(move_vec)
    split_planes=[plane_srf]
    #array the plane in z by vert space
    for i in range(1,plane_count):
        next_plane=Rhino.Geometry.Brep.DuplicateBrep(plane_srf)
        next_plane.Translate(i*move_vec)
        split_planes.append(next_plane)
    print "Number of split planes made = {}".format(len(split_planes))
    
    split_result=Rhino.Geometry.Brep.CreateBooleanSplit(objs,split_planes,tol)
    if split_result:
        print "Number of raw split results = {}".format(len(split_result))
        good_splits=[item for item in split_result if item is not None]
        if good_splits:
            print "Number of valid split results = {}".format(len(good_splits))
            [sc.doc.Objects.AddBrep(brep) for brep in good_splits]
            rs.DeleteObject(obj_id)
            sc.doc.Views.Redraw()
TestBoolSplit()

Sample file to test:
TestSplitFile.3dm (2.0 MB)

Here is the raw output from BooleanSplit method at a breakpoint… Look at all those None’s

The script is pretty simple, it just creates a vertical array of planes and then uses them to split the object(s). For the objects in the file which are 100mm high, the 10mm increment should split them into 10 parts. I get 18 raw split results for each.

BTW, I also did this with simple Brep.Split() and Cap and it works fine, so getting a result is not the issue, it’s just to understand how the Brep.BooleanSplit() method works. If the splitters were non-planar however, that would be a different story.

Hi @Helvetosaur,

I am able to repeat. Thanks for reporting.

https://mcneel.myjetbrains.com/youtrack/issue/RH-74950

– Dale