protected override void DoWork(System.ComponentModel.BackgroundWorker worker, System.ComponentModel.DoWorkEventArgs doWorkEventArgs) { const int passCount = 50; if (!UpdateProgressAndCheckCancelled(100, 100, "Triangulating surface 1/1", worker, doWorkEventArgs)) { return; } Mesh m = surface.ConvertToMesh(tolerance); // The plane used to slice the surface Plane pln = Plane.YZ; pln.Rotate(-Math.PI / 4, Vector3D.AxisZ); pln.Translate(0, 60, 0); List <Point3D> pointList = new List <Point3D>(); for (int i = 0; i < passCount; i++) { pln = pln.Offset(2); ICurve[] sectionCurves = m.Section(pln, 0); if (sectionCurves.Length > 0) { LinearPath pass = (LinearPath)sectionCurves[0]; ICurve[] offsetLp = pass.QuickOffset(ballToolRadius, pln); if (offsetLp != null) { if (i % 2 == 1) { offsetLp[0].Reverse(); } pointList.AddRange(((Entity)offsetLp[0]).Vertices); } } if (!UpdateProgressAndCheckCancelled(i, passCount, "Computing passes", worker, doWorkEventArgs)) { return; } } // raises approach and retract Point3D approach = (Point3D)pointList[0].Clone(); approach.Z += 20; pointList.Insert(0, approach); Point3D retract = (Point3D)pointList[pointList.Count - 1].Clone(); retract.Z += 40; pointList.Add(retract); // return the toolpath as a LinearPath entity toolPath = new LinearPath(pointList); }