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:
input1=blocks
rs.BooleanDifference(input0,input1)
rs.SelectObjects (input0)
more=6
while(more==6):
cutblocks()
more=rs.MessageBox("Do you want to cut more slots?",buttons=3)
if (more==7):
cutting()
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, 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)
rs.BooleanDifference(input0,input1,delete_input=True)
cutting()
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 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.