Boolean Difference in Rhino Script

Hello,
Can anybody please let me know why the following Boolean Difference is not working?
It still requires 2 arrInputs as Rhino Objects, but I cant figure out why my objects (cp & cp2) are not.

 Call Main()
 Sub main()

Dim strcr,ext,cp
strcr = Rhino.getobject("pick 1st")
ext = Rhino.ExtrudeCurveStraight(strcr, Array(0, 0, 0), Array(0, 0, 10))
cp = Rhino.CapPlanarHoles(ext)

   If Rhino.IsObjectSolid(cp) Then
	Rhino.print("THIS IS SOLID.")
	Dim cp2
	strcr = Rhino.getobject("pick 2nd")
	ext = Rhino.ExtrudeCurveStraight(strcr, Array(0, 0, 0), Array(0, 0, 10))
	cp2 = Rhino.CapPlanarHoles(ext)
	
	If Rhino.IsObjectSolid(cp2) Then
		Rhino.Print("THIS IS SOLID AS WELL.")
		Rhino.BooleanDifference cp, cp2
	End If
  Else
	Rhino.Print("The object is not Solid")
End If

End Sub

Having trouble with boolean difference over the last hour as well. It was working fine earlier. Any ideas?

@Vahab,

Rhino.BooleanDifference takes arrays as inputs for both sets of objects (cp, cp2).
In your case cp and cp2 are single string variables representing the extruded curves.
To make it work, try:
Rhino.BooleanDifference array(cp), array(cp2)
This way you are feeding the method with arrays (what it needs) containing a single object each.

hth,

–jarek

@Jarek
Thanks for your note,
It doesn’t work though.
I know that BooleanDifference has to be fed by arrays as objects.
I can use:

        Rhino.GetObject

to provide inputs for the booleandifference, however I would like to learn how to get that done by the method I first used.

@Petra_Winnwalker
Could you please provide your code here?

Be more specific, attach a file, show us what doesn’t work, what are you trying to achieve?

@Ncik
Sorry for the confusion,
The code is right on the top of this discussion.
@Jerek advised to replace

   Rhino.BooleanDifference cp, cp2

with

  Rhino.BooleanDifference array(cp), array(cp2) 

I meant that does not work either.

My goal is to have 2 drawn circles that have intersection with each other.
With this code I would expect to have the circles transformed into cylinders that-under booleandifference- their shared volume returned as the output.

I see, clearly the boolean was not a problem as it can work with single objects as input (the documentation is not clear on this one.). However, the problem in your script is the CapPlanarHoles method. It does only return True/False (success/failure). The variable used in the method still holds the resulting object.
See modified version of the script below:

Call Main()
Sub main()

	Dim strcr,cp,cp2
	strcr = Rhino.getobject("pick 1st")
	cp = Rhino.ExtrudeCurveStraight(strcr, Array(0, 0, 0), Array(0, 0, 10))
	Call Rhino.CapPlanarHoles(cp)

	If Rhino.IsObjectSolid(cp) Then
		Rhino.print("THIS IS SOLID.")
		strcr = Rhino.getobject("pick 2nd")
		cp2 = Rhino.ExtrudeCurveStraight(strcr, Array(0, 0, 0), Array(0, 0, 10))
		Call Rhino.CapPlanarHoles(cp2)
	
		If Rhino.IsObjectSolid(cp2) Then
			Rhino.Print("THIS IS SOLID AS WELL.")
			Rhino.BooleanDifference cp, cp2
		End If
	Else
		Rhino.Print("The object is not Solid")
	End If

End Sub

@Jarek
Thanks buddy,
I appreciate your notes as well :slight_smile:
As you mentioned I misunderstood that

  Rhino.CapPlanarHoles()

should return string, while in fact it returns Boolean.