SliceJob

Package: Libraries.Fabrication · Inherits from: Libraries.Language.Object

The SliceJob class runs the whole slicer from one Profile: every stage gets its settings from the profile, so nothing is hard-coded per printer. model -> TriangleMesh -> MeshSlicer -> ContourGenerator -> PathGenerator -> (TreeSupport, SkirtGenerator) -> PathOrderer -> GcodeWriter -> (BambuPackager) Run prints its progress (see SetVerbose) and the warnings the stages collected, prefixed with "warning:". SetQuiet(true) prints nothing at all; the warnings are still kept, and GetWarnings returns them. The Configure actions can also be used one at a time, to set up a single stage from a profile in a test.

Example Code

use Libraries.System.File
use Libraries.Game.Graphics.Models.Data.ModelLoader
use Libraries.Game.Graphics.Models.Data.ModelData
use Libraries.Fabrication.SliceJob
use Libraries.Fabrication.Profiles.ProfileManager

class Main
    action Main
        File file
        file:SetPath("assets/benchy.stl")
        ModelLoader loader
        ModelData model = loader:Load(file)

        ProfileManager profiles
        profiles:Load("Profiles/profiles.json")
        SliceJob job
        job:Run(model, profiles:Require("bambu-p2s"), "Outputs/benchy.gcode")
    end
end

Actions

GetDroppedPathCount()

How many paths the last Run left out because they were too short to print: details smaller than the printer's line.

Returns

integer: The number of paths left out.

Example

use Libraries.Fabrication.SliceJob

SliceJob job
// ... job:Run(model, profile, "Outputs/part.gcode") ...
output job:GetDroppedPathCount() + " paths too short to print"

GetDroppedSpeckCount()

How many tiny outlines the last Run dropped (smaller than the profile's minContourArea).

Returns

integer: The number of outlines dropped.

Example

use Libraries.Fabrication.SliceJob

SliceJob job
// ... job:Run(model, profile, "Outputs/part.gcode") ...
output job:GetDroppedSpeckCount() + " specks dropped"

GetProgress()

How far the current or last Run is, from 0 (starting) to 1 (done). It moves in steps, one for each stage of slicing, and plane by plane while the walls and fill are planned, so another thread can show it on a progress bar while Run works.

Returns

number: The progress, from 0 to 1.

Example

use Libraries.Fabrication.SliceJob

SliceJob job
// another thread runs job:Run(model, profile, "Outputs/part.gcode")
output (job:GetProgress() * 100) + "% done: " + job:GetStage()

GetStage()

What the current or last Run is doing, in a few words, such as "Writing G-code", or "Done" when it has finished.

Returns

text: The stage.

Example

use Libraries.Fabrication.SliceJob

SliceJob job
output job:GetStage()

GetWarnings()

The warnings from the last Run, without the "warning: " prefix, whether or not they were printed. Empty before the first Run.

Returns

Libraries.Containers.Array<text>: The warnings, in the order the stages reported them.

Example

use Libraries.Containers.Array
use Libraries.Fabrication.SliceJob

SliceJob job
job:SetQuiet(true)
// ... job:Run(model, profile, "Outputs/part.gcode") ...
Array<text> warnings = job:GetWarnings()
integer i = 0
repeat while i < warnings:GetSize()
    output warnings:Get(i)
    i = i + 1
end

Run(Libraries.Game.Graphics.Models.Data.ModelData data, Libraries.Fabrication.Profiles.Profile profile, text gcodePath)

Slices the model with the profile and writes the G-code to gcodePath. If the profile has write3mf on, also packages it as a Bambu .gcode.3mf next to it.

Parameters

Returns

text: The path of the last file written (the .gcode.3mf, or the .gcode).

Example

use Libraries.System.File
use Libraries.Game.Graphics.Models.Data.ModelLoader
use Libraries.Game.Graphics.Models.Data.ModelData
use Libraries.Fabrication.SliceJob
use Libraries.Fabrication.Profiles.ProfileManager

File file
file:SetPath("assets/3dbenchy.stl")
ModelLoader loader
ModelData model = loader:Load(file)
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
SliceJob job
text written = job:Run(model, profiles:Require("ender3-v2"), "Outputs/benchy.gcode")
output "Wrote " + written

Run(Libraries.Game.Graphics.Models.Data.ModelData data, Libraries.Fabrication.Profiles.Profile profile, Libraries.System.File gcodeFile)

Slices the model with the profile and writes the G-code to the file. If the profile has write3mf on, also packages it as a Bambu .gcode.3mf beside it, with the same name.

Parameters

Returns

Libraries.System.File: The last file written (the .gcode.3mf, or the G-code file).

Example

use Libraries.System.File
use Libraries.Game.Graphics.Models.Data.ModelLoader
use Libraries.Game.Graphics.Models.Data.ModelData
use Libraries.Fabrication.SliceJob
use Libraries.Fabrication.Profiles.ProfileManager

ModelLoader loader
ModelData model = loader:Load("assets/3dbenchy.stl")
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
File gcode
gcode:SetPath("Outputs/benchy.gcode")
SliceJob job
File written = job:Run(model, profiles:Require("ender3-v2"), gcode)

SetGeneratorName(text name)

The program named in the G-code it writes (see GcodeWriter:SetGeneratorName).

Parameters

  • name text: The name, for example "My Slicer".

Example

use Libraries.Fabrication.SliceJob

SliceJob job
job:SetGeneratorName("My Slicer")

SetQuiet(boolean toggle)

Whether Run prints nothing at all: no progress and no warnings (off by default). The warnings are still collected; read them with GetWarnings. Errors still stop Run with an alert.

Parameters

  • toggle boolean: True to print nothing.

Example

use Libraries.Containers.Array
use Libraries.Fabrication.SliceJob

SliceJob job
job:SetQuiet(true)
// ... job:Run(model, profile, "Outputs/part.gcode") ...
Array<text> warnings = job:GetWarnings()
output warnings:GetSize() + " warnings"

SetVerbose(boolean toggle)

Whether Run prints its progress and statistics (on by default). Warnings are printed either way, unless SetQuiet turns them off too.

Parameters

  • toggle boolean: True to print progress.

Example

use Libraries.Fabrication.SliceJob

SliceJob job
job:SetVerbose(false)       // only warnings are printed

Inherited Actions

3 actions from Libraries.Language.Object