Rhino hangs running a fairly basic c# script

I’ve tried this on both Windows and OS X using ScriptEditor in Rhino 8 and I get the same results. Here is the script:

using Rhino;
using Rhino.Geometry;
var surface = new PlaneSurface(Plane.WorldXY, new Interval(0, 10), new Interval(0, 10));
var brep = surface.ToBrep();
var splitLine = new LineCurve(new Point2d(0, 0), new Point2d(10, 10));
RhinoDoc.ActiveDoc.Objects.AddBrep(brep);
RhinoDoc.ActiveDoc.Objects.AddCurve(splitLine);
// If I stop here and use the split command in the UI it works fine, but if I run the following line it hangs
var splitBreps = brep.Split(new [] {splitLine}, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);

I’m pretty new to Rhino, so maybe I’m missing something obvious, any suggestions?

Thanks

Hi Jake,

I am still learning to code myself using C#. Admittedly, I used some ChatGPT to help me debug a bit, but found a solution. Others may chime in with something more elegant.

using Rhino;
using Rhino.Geometry;

var surface = new PlaneSurface(Plane.WorldXY, new Interval(0, 10), new Interval(0, 10));
var brep = surface.ToBrep();
var splitLine = new LineCurve(new Point3d(0, 0, 0), new Point3d(10, 10, 0));

RhinoDoc.ActiveDoc.Objects.AddBrep(brep);
RhinoDoc.ActiveDoc.Objects.AddCurve(splitLine);

Brep[] splitBreps = brep.Split(new Curve[] {splitLine}, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);

foreach (var splitBrep in splitBreps)
{
RhinoDoc.ActiveDoc.Objects.AddBrep(splitBrep);
}

// Redraw the document to reflect changes
RhinoDoc.ActiveDoc.Views.Redraw();

I changed to the forum category to scripting, this help get a proper response.

1 Like

Interesting, it seems that the key difference is using Point3d instead of Point2d. Strange that it works when I do the Split in UI vs in code w/ the same objects. Smells like a bug but this is a workaround, thanks.

It works with Point2d or Point3D. The main thing is you were missing the Curve[] and you needed the Brep[] and the foreach loop to complete the task.