diff --git a/Directory.Build.props b/Directory.Build.props index 5ffc8c4..d8e1a85 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,7 +2,7 @@ Extensions - 1.0.5 + 1.0.6 Extensions Authors Assorted components for Grasshopper. Grasshopper;Extensions;Robots diff --git a/src/Extensions.Grasshopper/Toolpaths/GCodeToolpath.cs b/src/Extensions.Grasshopper/Toolpaths/GCodeToolpath.cs index 04cd41d..fac2daf 100644 --- a/src/Extensions.Grasshopper/Toolpaths/GCodeToolpath.cs +++ b/src/Extensions.Grasshopper/Toolpaths/GCodeToolpath.cs @@ -1,4 +1,4 @@ -using Grasshopper.Kernel; +using Grasshopper.Kernel; using Rhino.Geometry; using Robots; using Robots.Grasshopper; @@ -29,6 +29,7 @@ void Inputs(GH_InputParamManager pManager) pManager.AddTextParameter("File", "F", "GCode file.", GH_ParamAccess.item); pManager.AddParameter(new TargetParameter(), "Target", "T", "Created targets will use the parameters of this reference target if they're not supplied in the G-code file.", GH_ParamAccess.item); pManager.AddPointParameter("Point alignment", "P", "Aligns the X axis of the tagets to look towards this point (in world coordinate system). If not supplied it will use the X axis of the reference target.", GH_ParamAccess.item); + pManager.AddBooleanParameter("Add bit", "A", "Add drill bit to tool.", GH_ParamAccess.item); pManager[2].Optional = true; } @@ -46,16 +47,18 @@ protected override void SolveInstance(IGH_DataAccess DA) string file = null; GH_Target target = null; Point3d? point = null; + bool addBit = false; if (!DA.GetData(0, ref file)) return; if (!DA.GetData(1, ref target)) return; DA.GetData(2, ref point); + if (!DA.GetData(3, ref addBit)) return; var alignment = Vector3d.XAxis; if (point.HasValue) alignment = (Vector3d)point.Value; - var toolpath = new Toolpaths.Milling.GCodeToolpath(file, target.Value as CartesianTarget, alignment); + var toolpath = new Toolpaths.Milling.GCodeToolpath(file, target.Value as CartesianTarget, alignment, addBit); var (tool, mcs, rapidStarts, ignored) = toolpath.Toolpath; DA.SetData(0, toolpath); diff --git a/src/Extensions/Toolpaths/Milling/GCodeToolpath.cs b/src/Extensions/Toolpaths/Milling/GCodeToolpath.cs index e9bbfdb..c34a5c8 100644 --- a/src/Extensions/Toolpaths/Milling/GCodeToolpath.cs +++ b/src/Extensions/Toolpaths/Milling/GCodeToolpath.cs @@ -1,4 +1,4 @@ -using Rhino.Geometry; +using Rhino.Geometry; using Robots; using gs; using static Extensions.GeometryUtil; @@ -9,14 +9,14 @@ public class GCodeToolpath : SimpleToolpath { public FiveAxisToRobots Toolpath { get; set; } - public GCodeToolpath(string file, CartesianTarget referenceTarget, Vector3d alignment) + public GCodeToolpath(string file, CartesianTarget referenceTarget, Vector3d alignment, bool addBit) { using var reader = File.OpenText(file); var parser = new GenericGCodeParser(); var code = parser.Parse(reader); - Toolpath = new FiveAxisToRobots(referenceTarget, alignment, code); + Toolpath = new FiveAxisToRobots(referenceTarget, alignment, code, addBit); _targets = Toolpath.Targets; } } @@ -43,25 +43,33 @@ public void Deconstruct(out Tool tool, out Frame mcs, out List rapidStarts, ignored = _ignored; } - internal FiveAxisToRobots(CartesianTarget refTarget, Vector3d alignment, GCodeFile file) + internal FiveAxisToRobots(CartesianTarget refTarget, Vector3d alignment, GCodeFile file, bool addBit) { _refTarget = refTarget; _alignment = alignment; - var constructionPlane = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.GetConstructionPlane().Plane; - constructionPlane.Origin = Point3d.Origin; var workPlane = _refTarget.Frame.Plane; - var xform = Transform.PlaneToPlane(Plane.WorldXY, workPlane); - constructionPlane.Transform(xform); + //var xform = Transform.PlaneToPlane(Plane.WorldXY, workPlane); + //var constructionPlane = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.GetConstructionPlane().Plane; + //constructionPlane.Origin = Point3d.Origin; + //constructionPlane.Transform(xform); - _mcs = new Frame(plane: constructionPlane, name: "MCS"); + _mcs = new Frame(plane: workPlane, name: "MCS"); _gCodeMap = new Dictionary<(GCodeLine.LType letter, int number), Action> - { - { (GCodeLine.LType.GCode, 0), RapidMove }, - { (GCodeLine.LType.GCode, 1), LinearMove}, - { (GCodeLine.LType.MCode, 6), ToolSet }, - }; + { + { (GCodeLine.LType.GCode, 0), RapidMove }, + { (GCodeLine.LType.GCode, 1), LinearMove} + }; + + if (addBit) + { + _gCodeMap.Add((GCodeLine.LType.MCode, 6), ToolSet); + } + else + { + _tool = _refTarget.Tool; + } Interpret(file); _rapidStarts.Add(Targets.Count - 1);