Cannot get BooleanDifference to work


I would appreciate if somebody can take a look at my script and tell me why BooleanDifference is not working .
My script:
#Cut slots from tabs, Max Zuijdendorp, November 2016

import rhinoscriptsyntax as rs

# Check if a layer "Cutting Blocks" exists, if not, add it.
if not rs.IsLayer("Cutting Blocks"):
    rs.AddLayer("Cutting Blocks", (0,255,255))

# Make "Cutting Blocks" the current layer
rs.CurrentLayer("Cutting Blocks")
input0 =()
blocks =()

def cutblocks():

	rs.Command ("_ExtractSrf _Pause")
	rs.Command ("_ExtrudeSrf _BothSides=yes _Solid=yes _DeleteInput=yes 10")
	blocks = rs.LastCreatedObjects()
	rs.SelectObjects (blocks)

def cutting():
	input0 = rs.GetObject("Pick a polysurface to cut from", rs.filter.polysurface)
	if input0:
		rs.SelectObjects (input0)	


	more=rs.MessageBox("Do you want to cut more slots?",buttons=3)
if (more==7):

This is the test file I am using: Cutting_test.3dm (59.4 KB)

The objective is to cut matching holes in the top polysurface for the tabs of the lower polysurface. I want to allow for slight differences in the height of the tabs, so the method I have chosen is to copy the top surfaces of the tabs, extrude those to a set distance (10 mm) on both sides, and subtract the resulting polysurfaces from the top polysurface.
I have inserted two SelectObjects statements to check visually if all the correct GUI’s are being created, which seems to be the case. Nevertheless, I cannot see any holes appearing in the top polysurface.
I have spent the best part of today to get it to work (and re-learning Rhino Python again…), so I would really appreciate some help.


(Chris Kuether ) #2

Max. the part ‘side’ is an extrusion, not a polysrf.


Chris, both parts were created the same way, by extruding a closed planar curve. Somehow the top ended up as a polysurface and the side as an extrusion. But it should not make a difference, in regular Rhino I can subtract either one from the other without problems.


It gets weirder. I created a new script going back to the absolute basics:

#Boolean Difference Testing, Max Zuijdendorp, November 2016

import rhinoscriptsyntax as rs

input0 =()
input1 =()

def cutting():
	input0 = rs.GetObject("Pick a polysurface to cut from", rs.filter.polysurface)
	if input0:
		input1 = rs.GetObject("Pick a polysurface to cut with", rs.filter.polysurface)


Now it works, but instead of just cutting a chunk out of the green polysurface, a new polysurface is created on the current layer, with the correct bit removed, but the old polysurface remains as well.
Maybe I should mention I am using a mac, if that makes any difference.


Hi Max,

blocks is treated as a local variable within cutblocks. A couple of ways to get this to work are to:

  • Pass shared arguments to and return shared values from the functions
  • Add global blocks after def cutblocks():

You should also add _Copy=Yes to the _ExtractSrf line.



Hi Steve, thanks for your comments. As for blocks not being global, I believe “blocks=()” just above the subroutine definitions takes care of that. I’ve had that error message, and defining it at high level took care of that.

And yes, I have to add _Copy=yes. Luckily, it is a sticky setting of _ExtractSrf, once set it does not change.