CurveBooleanDifference Inconsistency

Hi All,

I’ve been coming across a problem in one of my scripts and narrowed it down to the CurveBooleanDifference function in Rhino 5 (VBS).

I have a sample file and script to show the problem so would appreciate being able to send it to someone to investigate. Thanks.

Regards,

Shane.

Hi Shane - please post here, or send to tech@mcneel.com a simple example of the problem and script. Please include a link back here if sending to tech@mcneel.com

-Pascal

Thanks Pascal - finally found the upload button here.

Larger curve is the main curve for the script, smaller box-curves are the cut-outs. One works, the other does not. One is a copy of the other. Thx.

Regards,

Shane.

CurveBooleanTestScript.rvb (431 Bytes) FailedCutoutTest.3dm (367.8 KB)

Hi Shane - looks like it works, but you are leaving the original input object there so it may look like it did not - try:

Option Explicit

Call Main()
Sub Main()

	Dim strMainCurve
	Dim strCOCurve
	Dim arrResult
		
	strMainCurve = Rhino.GetObject("Select Main Curve.", 4, True)
	If isNull(strmainCurve) Then Exit Sub
	
	strCOCurve = Rhino.GetObject("SelectCutout Curve.", 4)
	If isNull(strCOCurve) Then Exit Sub
	
	arrResult = Rhino.CurveBooleanDifference(strMainCurve, strCOCurve)
	If Not isnull(arrResult) Then
		Rhino.MessageBox("Bool Diff Succeeded")
		Rhino.DeleteObject(strMainCurve)
		Rhino.DeleteObject(strCOCurve)
	Else
		Rhino.MessageBox("Bool Diff Failed")
	End If
	
End Sub

-Pascal

I doesn’t work on both cutout curves for me.
In my 3DM file, I named one of the curves “Curve that fails”. This is the one that doesn’t work for me. The other does.

Note that I’m using Rhino 5

Regards,

Shane.

Hi Shane - I see that fails in V5 - the larger curve has a seam point that is right at the intersection of the failure curve - use CrvSeam to move it to a corner, then SimplifyCrv.

-Pascal

Thanks Pascal.

Since this is run within a much larger and longer running script, it’s not possible to manually interview for these issues, but I’ll see what I can come up with.

Am I correct in saying it’s been resolved in Rhino 6?

Regards,

Shane.

Hi Sane- your script works in V6 for both curves. Verifying the seam automatically might be a bit of a pain - probably a good deal easier in Python/RhinoCommon.

-Pascal

Thanks Pascal.

I’m in the process of converting my scripts to Python, but with over 1million lines of code, it’s taking some time!
Thanks very much for your help.

Regards,

Shane.

@shanew06 - You can try this to force all seam points to a corner:

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc

def test():
    tol = sc.doc.ModelAbsoluteTolerance
    atol = sc.doc.ModelAngleToleranceRadians
    def filter_closed( rhino_object, geometry, component_index):
        
        if geometry.IsClosed:
            return True
        return False
        
    ids = rs.GetObjects("Select closed curves", 4, preselect=True, custom_filter = filter_closed)
    if not ids: return
    
    for id in ids:
        
        crv = rs.coercecurve(id)
        if crv.IsClosed:
            pt = crv.PointAtStart
            dom = crv.Domain
            rc, disc = crv.GetNextDiscontinuity(Rhino.Geometry.Continuity.G1_locus_continuous, dom.Min, dom.Max)
            print rc
            if rc:  crv.ChangeClosedCurveSeam(disc)
            crv.Simplify( Rhino.Geometry.CurveSimplifyOptions.All, tol, atol)
            sc.doc.Objects.Replace(id, crv)
            
test()


-Pascal

Thanks Pascal.

I actually just made some code to reset the CurveSeam to the midpoint of the line and that seems to work. I’m about to try it in my main code so will see how it goes. Thanks again.

Regards,

Shane.

I made a couple of hasty goofs – updated above so it might actually work. Time for bed I think.

-Pascal