Help on Boolean Operations

Hi everyone.

Here I come again with another problem I’m sure the solution of should be simple, yet I can’t wrap my head around it.

I have a whole bunch of code on the big node on the left, which seems to work fine. This code outputs a lot of things, but the two active breps nodes, connected to the outputs (next to the red and green sticky panels), are the ones that cause me trouble.
I’ve isolated the code that troubles me in another small ghpython node next to them, that is were you should look (screenshot related)


I want to substract all of the green breps, which are connected in a list on the x input, from the red brep, which is a simple extruded rectangle and is connected to the y input.

I want to output the red brep but with all the slits from the green breps cut at the right place and in the right angle.

I tried to use rs.BooleanDifference(x,y)
The code runs, but it gives me nothing. Not even a “null” or an error, just straight up nothing.
It’s a bit annoying, I’ve been trying workarounds since last week and can’t find a solution to this problem.

Thanks !

Hey! I just tried to recreate your problem.
I can’t see any reason to run it in a while loop, if you already have the cutting “scales” in a list. It runs fine with a list input on it’s own.

best.
/Jens

Hi !
Thanks for your reply. But that left me even more puzzled about this problem. Here’s why:
I tried to apply your method to my file. I get two weird things:
1 - I have to invert the x and y input, just as if the boolean difference was reversed. Here is a screenshot from the results if I try the same setup as in your screenshot:

2 - Even when I reverse the order, I get a weird list as an output and not a single brep as in your example.

here is a screenshot of the result if I try to change the input order:

So yeah I already tried your setup but I thought I had to do it in a loop to force the program to work on a single brep and not create a copy everytime it performs a boolean operation.

Do you have an idea what’s going on here and where’s my mistake considering it should work fine as you demonstrated in your example?

Thanks !

Hi, Not sur if this is okay but i’m just bumping this thread: It’s been a month since i’m trying to figure if this is a bug or if i’m doing something wrong.

Hello @nicolas.fryder,

No need to bump this thread, patience is sometimes key.

You should have provided a file to work with from the get-go. It would have been much simpler for people to inspect your problem and maybe come up with a solution. Screenshots of a partial definition don’t always provide the right amount of information, and make it harder for people - willing to help - to toy around, which is a big part of finding an answer.
Furthermore, time is precious for most people and reconstructing a problem, just to find an answer to somebody else’s problem, is tedious to say the least.

Now, in the spirit of the holidays, this is what I’ve come up with.

It is a rather simple pythonic solution using rhinocommon, instead of the rhinoscriptsyntax.
It takes three inputs: subFromBrep should input a single brep, subWithBreps should provide a flat list of breps, and verbose a True or False statement. The type hints of subWithBreps and subFromBrep must be set to Brep for this to work!

The script looks like this:

"""Performs boolean differences on a brep with a number of intersecting breps.
    Inputs:
        subFromBrep: A single brep to subtract from.
        subWithBreps: A list of breps to subtract with.
        verbose: True or False for outputting messages.
    Output:
        Result: The new brep, if successful, or None."""

__author__ = "p1r4t3b0y"


import Rhino.Geometry as rg


if verbose: print "ERRORS:"

tmp_brep = subFromBrep # is equal to the input Brep for the first iteration 
fails = 0

for i in range(len(subWithBreps)): # loop through all the subtraction breps
    # Perfom boolean difference for two breps at a time
    diff = rg.Brep.CreateBooleanDifference(tmp_brep, subWithBreps[i], 0.01)
    if (diff != None) and (len(diff) > 0): # if successful, tmp_brep is updated with the new brep 
        tmp_brep = diff[0] 
    else:  # if not unsuccessful, print and continue
        if verbose: print "! Boolean difference failed for brep at index %d." %(i)
        fails += 1
        continue

if verbose: 
    if fails == 0: 
        print "(no errors)"       
    print " "

# Output the final result
if verbose: print "SUMMARY:"
if fails == 0:
    if verbose: print "All boolean operations were successfull!"
    Result = tmp_brep
elif fails == len(subWithBreps):
    if verbose: print "All boolean operations failed!"
else:
    if verbose: 
        if len(subWithBreps)-fails > 1:
            print "%d boolean operations were successful, and %d failed." %(len(subWithBreps)-fails, fails)
        else:
            print "%d boolean operation was successful, and %d failed." %(len(subWithBreps)-fails, fails)
    Result = tmp_brep

The script seems to work flawlessly for my geometry, which consists integrally of closed breps. Unfortunately, I couldn’t test it on your geometry, which seems to be more complex. It should work fine though!

Happy holidays! :santa:

boolean_help_v1.gh (14.6 KB)