Click or drag to resize

BrepCreateBooleanDifference Method (IEnumerableBrep, IEnumerableBrep, Double, Boolean)

Compute the Solid Difference of two sets of Breps.

Namespace:  Rhino.Geometry
Assembly:  RhinoCommon (in RhinoCommon.dll)
Since: 6.0
Syntax
public static Brep[] CreateBooleanDifference(
	IEnumerable<Brep> firstSet,
	IEnumerable<Brep> secondSet,
	double tolerance,
	bool manifoldOnly
)

Parameters

firstSet
Type: System.Collections.GenericIEnumerableBrep
First set of Breps (the set to subtract from).
secondSet
Type: System.Collections.GenericIEnumerableBrep
Second set of Breps (the set to subtract).
tolerance
Type: SystemDouble
Tolerance to use for difference operation.
manifoldOnly
Type: SystemBoolean
If true, non-manifold input breps are ignored.

Return Value

Type: Brep
An array of Brep results or null on failure.
Remarks
The solid orientation of the breps make a difference when calling this function
Examples
using System.Collections.Generic;
using Rhino.Commands;

partial class Examples
{
  public static Rhino.Commands.Result BooleanDifference(Rhino.RhinoDoc doc)
  {
    Rhino.DocObjects.ObjRef[] objrefs;
    Result rc = Rhino.Input.RhinoGet.GetMultipleObjects("Select first set of polysurfaces",
                                                        false, Rhino.DocObjects.ObjectType.PolysrfFilter, out objrefs);
    if (rc != Rhino.Commands.Result.Success)
      return rc;
    if (objrefs == null || objrefs.Length < 1)
      return Rhino.Commands.Result.Failure;

    List<Rhino.Geometry.Brep> in_breps0 = new List<Rhino.Geometry.Brep>();
    for (int i = 0; i < objrefs.Length; i++)
    {
      Rhino.Geometry.Brep brep = objrefs[i].Brep();
      if (brep != null)
        in_breps0.Add(brep);
    }

    doc.Objects.UnselectAll();
    rc = Rhino.Input.RhinoGet.GetMultipleObjects("Select second set of polysurfaces",
      false, Rhino.DocObjects.ObjectType.PolysrfFilter, out objrefs);
    if (rc != Rhino.Commands.Result.Success)
      return rc;
    if (objrefs == null || objrefs.Length < 1)
      return Rhino.Commands.Result.Failure;

    List<Rhino.Geometry.Brep> in_breps1 = new List<Rhino.Geometry.Brep>();
    for (int i = 0; i < objrefs.Length; i++)
    {
      Rhino.Geometry.Brep brep = objrefs[i].Brep();
      if (brep != null)
        in_breps1.Add(brep);
    }

    double tolerance = doc.ModelAbsoluteTolerance;
    Rhino.Geometry.Brep[] breps = Rhino.Geometry.Brep.CreateBooleanDifference(in_breps0, in_breps1, tolerance);
    if (breps.Length < 1)
      return Rhino.Commands.Result.Nothing;
    for (int i = 0; i < breps.Length; i++)
      doc.Objects.AddBrep(breps[i]);
    doc.Views.Redraw();
    return Rhino.Commands.Result.Success;
  }
}
Python
import Rhino
import scriptcontext

def BooleanDifference():
    filter = Rhino.DocObjects.ObjectType.PolysrfFilter
    rc, objrefs = Rhino.Input.RhinoGet.GetMultipleObjects("Select first set of polysurfaces", False, filter)
    if rc != Rhino.Commands.Result.Success: return rc
    if not objrefs: return Rhino.Commands.Result.Failure

    in_breps0 = []
    for objref in objrefs:
        brep = objref.Brep()
        if brep: in_breps0.append(brep)

    scriptcontext.doc.Objects.UnselectAll()
    rc, objrefs = Rhino.Input.RhinoGet.GetMultipleObjects("Select second set of polysurfaces", False, filter)
    if rc != Rhino.Commands.Result.Success: return rc
    if not objrefs: return Rhino.Commands.Result.Failure

    in_breps1 = []
    for objref in objrefs:
        brep = objref.Brep()
        if brep: in_breps1.append(brep)

    tolerance = scriptcontext.doc.ModelAbsoluteTolerance
    breps = Rhino.Geometry.Brep.CreateBooleanDifference(in_breps0, in_breps1, tolerance)
    if not breps: return Rhino.Commands.Result.Nothing
    for brep in breps: scriptcontext.doc.Objects.AddBrep(brep)
    scriptcontext.doc.Views.Redraw()
    return Rhino.Commands.Result.Success

if __name__=="__main__":
    BooleanDifference()
See Also