Boolean Differce
Boolean operations are used to combine or subtract 3D objects. The main types of boolean operations are: This operation subtracts one or more objects from another object. It’s equivalent to the mathematical difference operation.
RhinoCommons
import Rhino
import scriptcontext
# Prompt to select the set of polysurfaces to subract from
first_set_result = Rhino.Input.RhinoGet.GetMultipleObjects("Select the polysurfaces to subract from", False, Rhino.DocObjects.ObjectType.Brep)
# Prompt to select the set of polysurfaces to subtract with
second_set_result = Rhino.Input.RhinoGet.GetMultipleObjects("Select the polysurfaces to subtract with", 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 difference
difference = Rhino.Geometry.Brep.CreateBooleanDifference(first_set, second_set, scriptcontext.doc.ModelAbsoluteTolerance)
# Bake the difference to the document
if difference:
for brep in difference:
scriptcontext.doc.Objects.AddBrep(brep)
rhinoscriptsyntax
import rhinoscriptsyntax as rs
# Prompt to select the set of polysurfaces to subract from
first_set_ids = rs.GetObjects("Select the first set of polysurfaces", 16)
# Prompt to select the set of polysurfaces to subtract with
second_set_ids = rs.GetObjects("Select the second set of polysurfaces", 16)
# Perform boolean difference
difference = rs.BooleanDifference(first_set_ids, second_set_ids)
🛠 Exercises
01: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍
01: 🦏⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🦏
02: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍
02: 🦏⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🦏
Solutions:
01: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍 01: 🦏⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🦏
02: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍 02: 🦏⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🦏