PrintSetup
Package: Libraries.Fabrication · Inherits from: Libraries.Language.Object
The PrintSetup class gets a loaded model ready for a 3D printer: which printer, how large, which side goes down, which parts print, and whether to add supports and a brim. It says how large the print will be and whether it fits on the printer's bed before anything is sliced, checks whether each part is a closed solid (see MeshCheck), and then writes the G-code with Print. Sizes: 1. Real size: the model's units times SetUnits (1000 for glTF files, whose units are meters; 1 for files in millimeters). 2. Fit to the bed: the longer side across the bed becomes 80% of the bed's shorter side, made smaller if needed to fit under its height. 3. Longest side: the model's longest side becomes this many millimeters.
Example Code
use Libraries.System.File
use Libraries.Game.Graphics.Models.Data.ModelLoader
use Libraries.Game.Graphics.Models.Data.ModelData
use Libraries.Fabrication.PrintSetup
use Libraries.Fabrication.Printers.CrealityEnder3
ModelLoader loader
ModelData model = loader:Load("Car/ToyCarCentered.gltf")
CrealityEnder3 printer
PrintSetup setup
setup:SetModel(model)
setup:SetPrinter(printer)
setup:SetUnits(1000)
setup:SetLongestSide(100)
output "Prints " + setup:GetPrintWidth() + " by " + setup:GetPrintDepth() + " by " + setup:GetPrintHeight() + " mm"
if setup:Fits()
File file
file:SetPath("Prints/ToyCar.gcode")
setup:Print(file)
end
Variables
integer FIT_TO_BEDinteger REAL_SIZEinteger LONGEST_SIDE: How much of the bed's shorter side the model's longer side covers, for FIT_TO_BED.
Actions
Fits()
This action returns true if the print fits on the printer's bed and under its height, as the model sits (it isn't turned on the bed).
Returns
boolean: True if it fits.
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
if not setup:Fits()
output "Too large for this printer."
end
GetCheck()
This action returns the check of the model's parts: their names, triangle counts, and whether each is a closed solid.
Returns
Libraries.Fabrication.Geometry.MeshCheck: The check.
Example
use Libraries.Fabrication.PrintSetup
use Libraries.Fabrication.Geometry.MeshCheck
PrintSetup setup
// setup:SetModel(model)
MeshCheck meshCheck = setup:GetCheck()
output meshCheck:GetPartCount() + " parts"
GetDroppedPathCount()
This action returns how many paths the last Print 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.PrintSetup
PrintSetup setup
if setup:GetDroppedPathCount() > 0
output "Some details were too small to print."
end
GetLongestSide()
This action returns the longest side used by SetLongestSide, in millimeters (100 until it is set).
Returns
number: The longest side.
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
output setup:GetLongestSide() + " mm"
GetModelBounds()
This action returns the box around the included parts, in the model file's own units and directions (before any scale or turn): the lowest and highest x, then y, then z, six numbers. With no parts included, all six are 0.
Returns
Libraries.Containers.Array<number>: The lowest and highest x, y and z.
Example
use Libraries.Containers.Array
use Libraries.Fabrication.PrintSetup
PrintSetup setup
// setup:SetModel(model)
Array<number> bounds = setup:GetModelBounds()
output "The model is " + (bounds:Get(1) - bounds:Get(0)) + " units wide"
GetPercentOfRealSize()
This action returns the size as a percent of the model's real size.
Returns
number: The percent; 100 is real size.
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
output setup:GetPercentOfRealSize() + "%"
GetPrintDepth()
This action returns how deep the print will be, front to back on the bed, in millimeters.
Returns
number: The depth.
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
output setup:GetPrintDepth() + " mm deep"
GetPrintHeight()
This action returns how tall the print will be, in millimeters.
Returns
number: The height.
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
output setup:GetPrintHeight() + " mm tall"
GetPrintWidth()
This action returns how wide the print will be, left to right on the bed, in millimeters.
Returns
number: The width.
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
output setup:GetPrintWidth() + " mm wide"
GetPrinter()
This action returns the printer, or undefined if none is set.
Returns
Libraries.Fabrication.Profiles.Profile: The printer.
Example
use Libraries.Fabrication.PrintSetup
use Libraries.Fabrication.Profiles.Profile
PrintSetup setup
Profile printer = setup:GetPrinter()
GetProgress()
This action returns how far the current or last Print is, from 0 to 1, so another thread can show it on a progress bar (see SliceJob:GetProgress).
Returns
number: The progress, from 0 to 1.
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
output (setup:GetProgress() * 100) + "% done"
GetScale()
This action returns how many millimeters one unit of the model becomes, for the size chosen. It is 0 until a model with included parts and a printer are set.
Returns
number: Millimeters per model unit.
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
// setup:SetModel(model), setup:SetPrinter(printer)
output setup:GetScale() + " mm per unit"
GetSizeMode()
This action returns which size is used: REAL_SIZE, FIT_TO_BED or LONGEST_SIDE.
Returns
integer: The size mode.
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
if setup:GetSizeMode() = setup:REAL_SIZE
output "Real size"
end
GetStage()
This action returns what the current or last Print is doing, such as "Writing G-code" (see SliceJob:GetStage).
Returns
text: The stage.
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
output setup:GetStage()
GetUpAxis()
This action returns which way is up in the model file: "Y", "Z" or "auto" (see SetUpAxis).
Returns
text: The up axis.
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
output setup:GetUpAxis()
GetWarnings()
This action returns the warnings from the last Print.
Returns
Libraries.Containers.Array<text>: The warnings.
Example
use Libraries.Containers.Array
use Libraries.Fabrication.PrintSetup
PrintSetup setup
Array<text> warnings = setup:GetWarnings()
HasBrim()
This action returns true if a brim is on (see SetBrim).
Returns
boolean: True for a brim.
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
output setup:HasBrim()
HasSupports()
This action returns true if supports are on (see SetSupports).
Returns
boolean: True for supports.
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
output setup:HasSupports()
IsPartIncluded(integer index)
This action returns true if a part prints.
Parameters
indexinteger: Which part, counting from 0.
Returns
boolean: True if it prints.
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
// setup:SetModel(model)
output setup:IsPartIncluded(0)
Print(Libraries.System.File file)
This action slices the included parts with the printer and the choices made, and writes the G-code to the file. With a Bambu printer that packages for Bambu (write3mf), a .gcode.3mf is written beside it.
Parameters
fileLibraries.System.File: Where to write the G-code.
Returns
Libraries.System.File: The last file written (the .gcode.3mf, or the G-code file).
Example
use Libraries.System.File
use Libraries.Fabrication.PrintSetup
PrintSetup setup
// setup:SetModel(model), setup:SetPrinter(printer)
File file
file:SetPath("Prints/ToyCar.gcode")
File written = setup:Print(file)
SetBrim(boolean toggle)
This action sets whether a brim is printed around the first layer, to help small contact areas stay on the bed.
Parameters
toggleboolean: True for a brim.
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
setup:SetBrim(true)
SetLongestSide(number millimeters)
This action prints the model so its longest side is this many millimeters.
Parameters
millimetersnumber: The longest side, in millimeters.
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
setup:SetLongestSide(100)
SetModel(Libraries.Game.Graphics.Models.Data.ModelData data)
This action sets the model to print. Every part starts out included, and every part is checked (see GetCheck).
Parameters
dataLibraries.Game.Graphics.Models.Data.ModelData: The loaded model.
Example
use Libraries.Game.Graphics.Models.Data.ModelLoader
use Libraries.Fabrication.PrintSetup
ModelLoader loader
PrintSetup setup
setup:SetModel(loader:Load("Car/ToyCarCentered.gltf"))
SetPartIncluded(integer index, boolean include)
This action sets whether a part prints. Parts are numbered as in GetCheck, counting from 0.
Parameters
indexinteger: Which part.includeboolean: True to print it.
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
// setup:SetModel(model)
setup:SetPartIncluded(1, false)
SetPrinter(Libraries.Fabrication.Profiles.Profile profile)
This action sets the printer, which gives the bed size and everything else the print uses. Load one with a printer class, such as CrealityEnder3, or from a ProfileManager.
Parameters
profileLibraries.Fabrication.Profiles.Profile: The printer.
Example
use Libraries.Fabrication.PrintSetup
use Libraries.Fabrication.Printers.CrealityEnder3
CrealityEnder3 printer
PrintSetup setup
setup:SetPrinter(printer)
SetSupports(boolean toggle)
This action sets whether supports are added under parts that hang out more than the printer's overhang angle.
Parameters
toggleboolean: True for supports.
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
setup:SetSupports(true)
SetUnits(number millimeters)
This action says how many millimeters one unit of the model file is, for its real size: 1000 for glTF files (meters), 1 for files in millimeters, 25.4 for files in inches.
Parameters
millimetersnumber: Millimeters per unit of the file.
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
setup:SetUnits(1000)
SetUpAxis(text axis)
This action says which way is up in the model file. "Y" (the default) keeps a model as it was made in most 3D tools and games, its bottom down. "Z" is for files made Z-up, such as most STL files. "auto" lets the slicer put the side with the most flat area down.
Parameters
axistext: "Y", "Z" or "auto".
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
setup:SetUpAxis("auto")
UseFitToBed()
This action prints the model as large as fits: its longer side across the bed becomes 80% of the bed's shorter side, smaller if needed to fit under the printer's height.
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
setup:UseFitToBed()
UseRealSize()
This action prints the model at its real size (see SetUnits).
Example
use Libraries.Fabrication.PrintSetup
PrintSetup setup
setup:UseRealSize()