static void Main(string[] args) { CappedCylinderGenerator cylgen = new CappedCylinderGenerator() { BaseRadius = 10, TopRadius = 5, Height = 20, Slices = 32 }; DMesh3 mesh = cylgen.Generate().MakeDMesh(); MeshTransforms.ConvertYUpToZUp(mesh); // g3 meshes are usually Y-up // center mesh above origin AxisAlignedBox3d bounds = mesh.CachedBounds; Vector3d baseCenterPt = bounds.Center - bounds.Extents.z * Vector3d.AxisZ; MeshTransforms.Translate(mesh, -baseCenterPt); // create print mesh set PrintMeshAssembly meshes = new PrintMeshAssembly(); meshes.AddMesh(mesh, PrintMeshOptions.Default()); // create settings //MakerbotSettings settings = new MakerbotSettings(Makerbot.Models.Replicator2); //PrintrbotSettings settings = new PrintrbotSettings(Printrbot.Models.Plus); //MonopriceSettings settings = new MonopriceSettings(Monoprice.Models.MP_Select_Mini_V2); RepRapSettings settings = new RepRapSettings(RepRap.Models.Unknown); // do slicing MeshPlanarSlicer slicer = new MeshPlanarSlicer() { LayerHeightMM = settings.LayerHeightMM }; slicer.Add(meshes); PlanarSliceStack slices = slicer.Compute(); // run print generator SingleMaterialFFFPrintGenerator printGen = new SingleMaterialFFFPrintGenerator(meshes, slices, settings); if (printGen.Generate()) { // export gcode GCodeFile gcode = printGen.Result; using (StreamWriter w = new StreamWriter("c:\\demo\\cone.gcode")) { StandardGCodeWriter writer = new StandardGCodeWriter(); writer.WriteFile(gcode, w); } } }
public IEnumerable <Progress> GenerateGCodeFile() { // run print generator // do slicing var slicer = new MeshPlanarSlicer() { LayerHeightMM = settings.LayerHeightMM }; slicer.Add(meshes); foreach (var i in slicer.Compute()) { yield return(i); } PlanarSliceStack slices = slicer.Result; var printGen = new SingleMaterialFFFPrintGenerator(meshes, slices, settings); foreach (var i in printGen.Generate()) { yield return(i); } gcode = printGen.Result; }
static string GenerateGCodeForMeshes(PrintMeshAssembly meshes) { bool ENABLE_SUPPORT_ZSHIFT = true; // configure settings //MakerbotSettings settings = new MakerbotSettings(Makerbot.Models.Replicator2); //FlashforgeSettings settings = new FlashforgeSettings(Flashforge.Models.CreatorPro); //MonopriceSettings settings = new MonopriceSettings(Monoprice.Models.MP_Select_Mini_V2); PrintrbotSettings settings = new PrintrbotSettings(Printrbot.Models.Plus); //PrusaSettings settings = new PrusaSettings(Prusa.Models.i3_MK3); //settings.ExtruderTempC = 215; //settings.Machine.NozzleDiamMM = 0.4; settings.Shells = 2; settings.InteriorSolidRegionShells = 0; settings.SparseLinearInfillStepX = 5; //settings.SolidFillNozzleDiamStepX = 0; //settings.SolidFillBorderOverlapX = 0; //settings.SparseFillBorderOverlapX = 0; settings.ClipSelfOverlaps = false; //settings.RoofLayers = settings.FloorLayers = 0; //settings.LayerRangeFilter = new Interval1i(245, 255); //settings.LayerRangeFilter = new Interval1i(0, 0); settings.EnableBridging = true; settings.GenerateSupport = false; settings.EnableSupportShell = true; settings.SupportMinZTips = false; settings.SupportSolidSpace = 0.35; settings.SupportOverhangAngleDeg = 25; //settings.OuterShellLast = true; //settings.Shells = 0; //settings.Machine.NozzleDiamMM = 0.75; //settings.Machine.MaxLayerHeightMM = 0.5; //settings.FillPathSpacingMM = settings.Machine.NozzleDiamMM; //settings.LayerHeightMM = 0.5; settings.StartLayers = 0; settings.StartLayerHeightMM = 0.3; //settings.LayerRangeFilter = new Interval1i(130, 140); LastSettings = settings.CloneAs <SingleMaterialFFFSettings>(); System.Console.WriteLine("Slicing..."); // slice meshes MeshPlanarSlicer slicer = new MeshPlanarSlicer() { LayerHeightMM = settings.LayerHeightMM }; if (settings.StartLayers > 0) { int start_layers = settings.StartLayers; double std_layer_height = settings.LayerHeightMM; double start_layer_height = settings.StartLayerHeightMM; slicer.LayerHeightF = (layer_i) => { return((layer_i < start_layers) ? start_layer_height : std_layer_height); }; } slicer.Add(meshes); PlanarSliceStack slices = slicer.Compute(); System.Console.WriteLine("Generating GCode..."); // run print generator SingleMaterialFFFPrintGenerator printGen = new SingleMaterialFFFPrintGenerator(meshes, slices, settings); if (ENABLE_SUPPORT_ZSHIFT) { printGen.LayerPostProcessor = new SupportConnectionPostProcessor() { ZOffsetMM = 0.2f } } ; printGen.AccumulatePathSet = (SHOW_RELOADED_GCODE_PATHS == false); printGen.Generate(); GCodeFile genGCode = printGen.Result; System.Console.WriteLine("Writing GCode..."); string sWritePath = "../../../sample_output/generated.gcode"; StandardGCodeWriter writer = new StandardGCodeWriter(); using (StreamWriter w = new StreamWriter(sWritePath)) { writer.WriteFile(genGCode, w); } if (settings is ISailfishSettings) { System.Diagnostics.Process.Start(GPX_PATH, (settings as ISailfishSettings).GPXModelFlag + " -p " + sWritePath); } View.PathDiameterMM = (float)settings.Machine.NozzleDiamMM - 0.005f; if (SHOW_RELOADED_GCODE_PATHS == false) { View.SetPaths(printGen.AccumulatedPaths, settings); View.SetSlices(slices); } return(sWritePath); }