As you see in the video, for a bunch of curves, if I select an outer point I get combined regions combining all curves closed or open.
How do I do this programatically ?
RhinoCommon does not expose CurveBoolean’s region-picking as one call.
I also cannot specify a Point3D for the outside point.
Thanks @dale for looking into this.
You have a file with several curves.
Note that units are in mm and absolute tolerance is set to 1 unit.
On most of these groups the curve boolean works well from Rhino. 260115 Curve boolean from API.3dm (4.5 MB)
Curve.CreateBooleanRegions is a bad strategy because:
All regions must have a point (from the documentation)
I have too many curves, it will run into trouble when trying to boolean all of them.
Self-intersections of curves produce failures.
What CurveBoolean does in Rhino with CombineRegions=Yes, AllRegions=Yes and a single point specified outside the desired region is something different and in my opinion it is not exposed in RhinoCommon or rhinoscriptsyntax.
I didn’t see your original case in the Rhino file (and might not be fully understanding the issue), but here’s a quick go with the first three cases from your Rhino file:
#CurveBooleanRegions
import Rhino
import scriptcontext as sc
import rhinoscriptsyntax as rs
def create_boolean_region_curves():
# Select curves
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select intersecting curves")
go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve
go.SubObjectSelect = False
go.GroupSelect = True
go.GetMultiple(2, 0)
if go.CommandResult() != Rhino.Commands.Result.Success:
return
crvs = []
for i in range(go.ObjectCount):
c = go.Object(i).Curve()
if c: crvs.append(c.DuplicateCurve())
if not crvs:
return
# Determine plane (try from first planar curve, else WorldXY)
plane = Rhino.Geometry.Plane.WorldXY
ok, pln = crvs[0].TryGetPlane()
if ok:
plane = pln
# Options
tol = sc.doc.ModelAbsoluteTolerance
combine = True
# Compute boolean regions
regs = Rhino.Geometry.Curve.CreateBooleanRegions(crvs, plane, combine, tol)
if not regs or regs.RegionCount == 0:
print("No regions found (check curve intersections / planarity / tolerance).")
return
# Add resulting region boundary curves to document
new_ids = []
for i in range(regs.RegionCount):
region_crvs = regs.RegionCurves(i) # boundary curves for this region
for rc in region_crvs:
if rc:
new_ids.append(sc.doc.Objects.AddCurve(rc))
sc.doc.Views.Redraw()
print("Created {} region boundary curves (from {} regions).".format(len(new_ids), regs.RegionCount))
if __name__ == "__main__":
create_boolean_region_curves()