Boolean Intersection


Boolean operations are used to combine or subtract 3D objects. The main types of boolean operations are:

This operation creates a new object that is the common volume of two or more objects. It’s equivalent to the mathematical intersection operation.


RhinoCommons


import Rhino
import scriptcontext

# Prompt to select the first set of polysurfaces
first_set_result = Rhino.Input.RhinoGet.GetMultipleObjects("Select the first set of polysurfaces", False, Rhino.DocObjects.ObjectType.Brep)

# Prompt to select the second set of polysurfaces
second_set_result = Rhino.Input.RhinoGet.GetMultipleObjects("Select the second set of polysurfaces", False, Rhino.DocObjects.ObjectType.Brep)

# Extract the breps from the object references
first_set = [obj_ref.Brep() for obj_ref in first_set_result[1]]
second_set = [obj_ref.Brep() for obj_ref in second_set_result[1]]

# Create the boolean intersection
intersection = Rhino.Geometry.Brep.CreateBooleanIntersection(first_set, second_set, scriptcontext.doc.ModelAbsoluteTolerance)

# Bake the intersection to the document
if intersection:
    for brep in intersection:
        scriptcontext.doc.Objects.AddBrep(brep)


rhinoscriptsyntax


import rhinoscriptsyntax as rs

# Prompt to select the first set of polysurfaces
first_set_ids = rs.GetObjects("Select the first set of polysurfaces", 16)

# Prompt to select the second set of polysurfaces
second_set_ids = rs.GetObjects("Select the second set of polysurfaces", 16)

# Perform boolean intersection
intersection = rs.BooleanIntersection(first_set_ids, second_set_ids)


🛠 Exercises


00: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍

00: 🦏⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🦏

Solutions:

01: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍

01: 🦏⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🦏