Python BooleanIntersection problem

Can someone tell me why the results of the two scripts are different - especially why the result of ScriptTest2 is seemingly “wrong”? Run “Test 1” on the two volumes in the file picking first “A” then “B”… then run “Test 2” on the two surfaces doing the same… Script Test 2 should just extrude the flat surfaces to the same boxes that are used for Script Test 1 before doing the Boolean Intersection… What stupid thing am I overlooking here? Thanks, --Mitch

BooleanIntersectTest.3dm(105.1 KB)

Test1.py(610 Bytes)

Test2.py(873 Bytes)

OK, more on this… If I use the code below - which is essentially the same as Test2 above - I get the same problem. But if I invert the extrusion direction - that is to say extrude in the -Z direction - the result is what I expect… Why? A Boolean intersection between two solids like that should always give the same result… Curiouser and curiouser…

import rhinoscriptsyntax as rs
import Rhino, scriptcontext
    
def Test2():
    tol=scriptcontext.doc.ModelAbsoluteTolerance
    msg="Select base surface, then difference surface"
    srfs=rs.GetObjects(msg,8,minimum_count=2,maximum_count=2)
    if not srfs: return

    #extrude both surfaces solid one unit in plane Z direction
    plane=rs.WorldXYPlane()
    line=Rhino.Geometry.Line(rs.coerce3dpoint((0,0,0)),rs.coerce3dpoint((0,0,1)))
    # to extrude negative, uncomment line below, comment out line above
    #line=Rhino.Geometry.Line(rs.coerce3dpoint((0,0,0)),rs.coerce3dpoint((0,0,-1)))
    br0 = rs.coercebrep(srfs[0])
    br1 = rs.coercebrep(srfs[1])

    solid0 = br0.Faces[0].CreateExtrusion(line.ToNurbsCurve(), cap=True)
    solid1 = br1.Faces[0].CreateExtrusion(line.ToNurbsCurve(), cap=True)

    solDiff = Rhino.Geometry.Brep.CreateBooleanIntersection(solid0, solid1, tol)    
    if solDiff:
        for brep in solDiff:
            scriptcontext.doc.Objects.AddBrep(brep)
    rs.DeleteObjects(srfs)

Test2()

Any answers…?

I’m going to try and look at this later today. Sorry for the delay

I’ve been staring at this for quite a while and still haven’t quite figured out what is causing the problem. It is obviously a bug in Rhino, but I just can’t see the point where things go bad. It’s driving me crazy :confounded:

Rhino is doing some sort of “clean-up” since adding the following to the Test2 script makes things work

    ...
    solid0 = br0.Faces[0].CreateExtrusion(line.ToNurbsCurve(), cap=True)
    solid1 = br1.Faces[0].CreateExtrusion(line.ToNurbsCurve(), cap=True)
    id0 = scriptcontext.doc.Objects.AddBrep(solid0)
    id1 = scriptcontext.doc.Objects.AddBrep(solid1)
    solid0=rs.coercebrep(id0)
    solid1=rs.coercebrep(id1)
    ...

This shouldn’t be necessary though and is just a hack while I’m figuring out what is going on.

OK, thanks for looking into it Steve - hopefully it won’t cause you nightmares… :scream:
Cheers,
–Mitch