Polyline to Brep.CreateBooleanDifference

Hi - noob here,

I have been trying to use Brep.CreateBooleanDifference but am not getting any results.

I have some simple shapes as Polylines, extruding to Surfaces and converting to Brep. These look correct when I add the Brep to the RhinoDoc. But when I do the Brep.CreateBooleanDifference on two overlapping Breps the result is null (unless I crank the tolerance right up).

I suspect it is something to do with the Surfaces/Breps not being solid (I might be wrong) but can’t see a way to make them solid at any step of the process.


Difficult to say without an example case, but try to avoid overlapping or tangent surfaces.
For example, while extruding polylines and later using one solid to subtract from the other, extrude the subtracting solid by a bigger value than the other.

At first, ensure your input Polyline is closed, planar and valid.
Then, I suspect the Brep created by extruding a polyline is not automatically closed, you may have a look to this method: https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Brep_CapPlanarHoles.htm

Maybe this dirty example will help you:

public static Brep BrepExtrusionFromCurve(Curve curve, double thickness, Plane plane)
  if (!curve.IsPlanar(tolerance)
    throw new InvalidOperationException("Input curve is not planar");

  if (!curve.IsClosed)
    throw new InvalidOperationException("Input curve is not closed");

  var extrusion = Extrusion.CreateExtrusion(curve, thickness * plane.ZAxis);

  var brep = extrusion.ToBrep();
  if (!brep.IsValid)
      throw new InvalidOperationException("Output brep is not valid");

  var cappedBrep = brep.CapPlanarHoles(tolerance);

  if (!cappedBrep.IsValid)
     throw new InvalidOperationException("Output capped brep is not valid");

  return cappedBrep;

Also if you begin with Rhinocommon, don’t hesitate to run you code in debug mode and put breakpoints at interesting places to inspect the state of the different objects you are instantiating and how they evolve. For instance, you can watch the Brep.IsSolid property to check whether your Brep is closed or not.


It was the command that I was missing.