protected override void SolveInstance(IGH_DataAccess DA) { List <Toolpath> tpIn = new List <Toolpath>(); object safety = null; DA.GetDataList("Toolpaths", tpIn); DA.GetData("Safety", ref safety); List <Toolpath> TP = tpIn.Select(x => x.Duplicate()).ToList(); // Program initialization CMSPost cms = new CMSPost(); cms.Author = "Tom Svilans"; cms.Name = "TestPost"; cms.StockModel = null; for (int i = 0; i < TP.Count; ++i) { cms.AddTool(TP[i].Tool); cms.AddPath(TP[i]); } //cms.WorkOffset = new Point3d(0, 0, 0); // Post-process toolpaths var code = (cms.Compute() as List <string>).Select(x => new GH_String(x)); // ****** Fun stuff ends here. ****** List <Point3d> points = new List <Point3d>(); List <int> types = new List <int>(); List <Vector3d> vectors = new List <Vector3d>(); for (int i = 0; i < cms.Paths.Count; ++i) { for (int j = 0; j < cms.Paths[i].Paths.Count; ++j) { for (int k = 0; k < cms.Paths[i].Paths[j].Count; ++k) { points.Add(cms.Paths[i].Paths[j][k].Plane.Origin); vectors.Add(cms.Paths[i].Paths[j][k].Plane.ZAxis); if (cms.Paths[i].Paths[j][k].IsRapid()) { types.Add(0); } else if (cms.Paths[i].Paths[j][k].IsFeed()) { types.Add(1); } else if (cms.Paths[i].Paths[j][k].IsPlunge()) { types.Add(2); } else { types.Add(-1); } } } } Polyline poly = new Polyline(points); List <Line> lines = new List <Line>(); for (int i = 1; i < poly.Count; ++i) { lines.Add(new Line(poly[i - 1], poly[i])); } types.RemoveAt(0); DA.SetDataList("Gcode", code); DA.SetDataList("Path", lines); }
protected override void SolveInstance(IGH_DataAccess DA) { List <Toolpath> tpIn = new List <Toolpath>(); object safety = null; string post_name = ""; bool post_all = false; Plane frame = Plane.WorldXY; DA.GetData("Machine", ref post_name); this.Message = post_name; DA.GetDataList("Toolpaths", tpIn); DA.GetData("Safety", ref safety); DA.GetData("Frame", ref frame); DA.GetData("All codes", ref post_all); List <Toolpath> TP = tpIn.Select(x => x.Duplicate()).ToList(); MachinePost post = null; switch (post_name) { case ("CMS"): post = new CMSPost(); break; case ("Haas"): post = new HaasPost(); break; case ("Shopbot"): post = new ShopbotPost(); break; case ("Raptor"): post = new RaptorBCNPost(); break; case ("CNC-STEP"): post = new CncStepPost(); break; default: AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"Machine {post_name} not found."); return; } // Program initialization var doc = OnPingDocument(); if (doc != null) { post.Author = doc.Author.Name; post.Name = doc.DisplayName; } else { post.Author = "Author"; post.Name = "Post"; } post.StockModel = null; post.AlwaysWriteGCode = post_all; for (int i = 0; i < TP.Count; ++i) { var toolpath = TP[i]; post.AddTool(toolpath.Tool); if (frame != Plane.WorldXY) { toolpath.Transform(Transform.PlaneToPlane(Plane.WorldXY, frame)); } post.AddPath(toolpath); } //cms.WorkOffset = new Point3d(0, 0, 0); // Post-process toolpaths var code = (post.Compute() as List <string>).Select(x => new GH_String(x)); // ****** Fun stuff ends here. ****** List <Point3d> points = new List <Point3d>(); List <int> types = new List <int>(); List <Vector3d> vectors = new List <Vector3d>(); for (int i = 0; i < post.Paths.Count; ++i) { for (int j = 0; j < post.Paths[i].Paths.Count; ++j) { for (int k = 0; k < post.Paths[i].Paths[j].Count; ++k) { points.Add(post.Paths[i].Paths[j][k].Plane.Origin); vectors.Add(post.Paths[i].Paths[j][k].Plane.ZAxis); if (post.Paths[i].Paths[j][k].IsRapid()) { types.Add(0); } else if (post.Paths[i].Paths[j][k].IsFeed()) { types.Add(1); } else if (post.Paths[i].Paths[j][k].IsPlunge()) { types.Add(2); } else { types.Add(-1); } } } } Polyline poly = new Polyline(points); List <Line> lines = new List <Line>(); for (int i = 1; i < poly.Count; ++i) { lines.Add(new Line(poly[i - 1], poly[i])); } types.RemoveAt(0); DA.SetDataList("Gcode", code); DA.SetDataList("Path", lines); DA.SetDataList("debug", post.Errors); if (post.Axes != null) { var axes = new List <string>(); foreach (var values in post.Axes) { axes.Add($"{values.X:0.000}, {values.Y:0.000}, {values.Z:0.000}, {values.B:0.000}, {values.C:0.000}"); } DA.SetDataList("Axes", axes); DA.SetDataList("Speeds", post.Axes.Select(x => x.Speed)); } }