BambuPackager
Package: Libraries.Fabrication.Printing.Bambu · Inherits from: Libraries.Language.Object
The BambuPackager class packages a G-code file as a Bambu Lab .gcode.3mf (single plate), the archive Bambu Studio writes for "Export plate sliced file", so it can be sent to a Bambu printer. It reads the print time, layers, filament use and temperatures back from the G-code, draws the thumbnails, and fills in a settings template (see BambuProjectSettings): a project_settings.config from a .gcode.3mf that your own Bambu Studio exported for the same printer and filament. Only the values that describe this print are changed in it. The G-code must have Bambu's header block (GcodeWriter:SetBambuExtras) and should select T0 (Bambu's M620 S0A / T0 / M621 S0A blocks in the start code) so the printer can map filament 1 to an AMS slot or the external spool. Relative paths are resolved against the folder the program runs in; in Quorum Studio that is the project folder.
Example Code
use Libraries.Fabrication.Printing.Bambu.BambuPackager
class Main
action Main
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
packer:SetFilamentColor("#FFFFFF")
text archive = packer:Pack("Outputs/cube.gcode") // writes Outputs/cube.gcode.3mf
output "Wrote " + archive + ": " + packer:GetFilamentGrams() + " g"
end
end
Actions
GetFilamentGrams()
The filament's weight (g), from its length, diameter and type.
Returns
number: The filament's weight (g), from its length, diameter and type.
Example
use Libraries.Fabrication.Printing.Bambu.BambuPackager
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
text archive = packer:Pack("Outputs/cube.gcode")
output packer:GetFilamentGrams() + " g of filament"
GetFilamentLength()
The filament the last Pack's G-code extrudes (mm).
Returns
number: The filament the last Pack's G-code extrudes (mm).
Example
use Libraries.Fabrication.Printing.Bambu.BambuPackager
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
text archive = packer:Pack("Outputs/cube.gcode")
output packer:GetFilamentLength() + " mm of filament"
GetLayerCount()
The number of layers the last Pack read from the G-code header.
Returns
integer: The number of layers the last Pack read from the G-code header.
Example
use Libraries.Fabrication.Printing.Bambu.BambuPackager
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
text archive = packer:Pack("Outputs/cube.gcode")
output packer:GetLayerCount() + " layers"
GetPrintSeconds()
The print time the last Pack read from the G-code header (s).
Returns
integer: The print time the last Pack read from the G-code header (s).
Example
use Libraries.Fabrication.Printing.Bambu.BambuPackager
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
text archive = packer:Pack("Outputs/cube.gcode")
output packer:GetPrintSeconds() + " s"
GetPrintTime()
The print time as text, such as "1h 2m 3s".
Returns
text: The print time as text, such as "1h 2m 3s".
Example
use Libraries.Fabrication.Printing.Bambu.BambuPackager
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
text archive = packer:Pack("Outputs/cube.gcode")
output "Printing takes " + packer:GetPrintTime()
GetSettingsVersion()
The Bambu Studio version the settings template came from.
Returns
text: The Bambu Studio version the settings template came from.
Example
use Libraries.Fabrication.Printing.Bambu.BambuPackager
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
text archive = packer:Pack("Outputs/cube.gcode")
output "Settings from Bambu Studio " + packer:GetSettingsVersion()
GetWarnings()
Warnings from the last Pack, as sentences.
Returns
Libraries.Containers.Array<text>: Warnings from the last Pack, as sentences.
Example
use Libraries.Containers.Array
use Libraries.Fabrication.Printing.Bambu.BambuPackager
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
text archive = packer:Pack("Outputs/cube.gcode")
Array<text> warnings = packer:GetWarnings()
integer i = 0
repeat while i < warnings:GetSize()
output "warning: " + warnings:Get(i)
i = i + 1
end
Pack(text gcodePath)
Packages gcodePath as gcodePath without ".gcode", plus ".gcode.3mf". Returns the output path.
Parameters
gcodePathtext: The G-code file, written with Bambu extras on.
Returns
text: The path of the archive written.
Example
use Libraries.Fabrication.Printing.Bambu.BambuPackager
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
text archive = packer:Pack("Outputs/cube.gcode")
output "Wrote " + archive
Pack(Libraries.System.File gcodeFile, Libraries.System.File outputFile)
Packages a G-code file as the output file. Returns the output file.
Parameters
gcodeFileLibraries.System.File: The G-code file, written with Bambu extras on.outputFileLibraries.System.File: Where to write the archive.
Returns
Libraries.System.File: outputFile.
Example
use Libraries.System.File
use Libraries.Fabrication.Printing.Bambu.BambuPackager
File gcode
gcode:SetPath("Outputs/cube.gcode")
File archive
archive:SetPath("Outputs/plates/cube.gcode.3mf")
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
packer:Pack(gcode, archive)
Pack(text gcodePath, text outputPath)
Packages gcodePath as outputPath. Returns the output path.
Parameters
gcodePathtext: The G-code file, written with Bambu extras on.outputPathtext: Where to write the archive.
Returns
text: outputPath.
Example
use Libraries.Fabrication.Printing.Bambu.BambuPackager
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
text archive = packer:Pack("Outputs/cube.gcode", "Outputs/plates/cube.gcode.3mf")
Pack(Libraries.System.File gcodeFile)
Packages a G-code file as a .gcode.3mf beside it, with the same name. Returns the archive.
Parameters
gcodeFileLibraries.System.File: The G-code file, written with Bambu extras on.
Returns
Libraries.System.File: The archive written.
Example
use Libraries.System.File
use Libraries.Fabrication.Printing.Bambu.BambuPackager
File gcode
gcode:SetPath("Outputs/cube.gcode")
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
File archive = packer:Pack(gcode)
Scan(text gcode)
Reads time, layers, height, filament use, temperatures, first-layer time and XY extrusion segments (for the thumbnail and bounding box) from the G-code. Pack calls this; it is public so the numbers can be inspected.
Parameters
gcodetext: The G-code text.
Example
use Libraries.System.File
use Libraries.Fabrication.Printing.Bambu.BambuPackager
File file
file:SetPath("Outputs/cube.gcode")
BambuPackager packer
packer:Scan(file:Read())
output packer:GetLayerCount() + " layers, " + packer:GetFilamentLength() + " mm of filament"
SetBedType(text type)
textured_plate, hot_plate, eng_plate, cool_plate or supertack_plate.
Parameters
typetext: The plate.
Example
use Libraries.Fabrication.Printing.Bambu.BambuPackager
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
packer:SetBedType("textured_plate")
text archive = packer:Pack("Outputs/cube.gcode")
SetFilamentColor(text color)
The colour shown on the filament mapping screen, as #RRGGBB.
Parameters
colortext: The colour, such as "#FF8000".
Example
use Libraries.Fabrication.Printing.Bambu.BambuPackager
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
packer:SetFilamentColor("#FF8000")
text archive = packer:Pack("Outputs/cube.gcode")
SetFilamentId(text id)
Bambu filament ID. If not set, the generic ID for the filament type is used.
Parameters
idtext: The filament ID, such as "GFA00".
Example
use Libraries.Fabrication.Printing.Bambu.BambuPackager
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
packer:SetFilamentId("GFA00") // Bambu PLA Basic
text archive = packer:Pack("Outputs/cube.gcode")
SetFilamentType(text type)
PLA, PETG, ABS, ASA, TPU, PC or PA.
Parameters
typetext: The material.
Example
use Libraries.Fabrication.Printing.Bambu.BambuPackager
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
packer:SetFilamentType("PETG")
text archive = packer:Pack("Outputs/cube.gcode")
SetGeneratorName(text name)
The program named in the header block, as for GcodeWriter:SetGeneratorName.
Parameters
nametext: The name.
Example
use Libraries.Fabrication.Printing.Bambu.BambuPackager
BambuPackager packer
packer:SetSettingsTemplate("p2s_project_settings.json")
packer:SetGeneratorName("My Slicer")
text archive = packer:Pack("cube.gcode")
SetLayerHeight(number height)
If not set (or 0), the layer height is read from the G-code's "Layer height:" comment.
Parameters
heightnumber: The layer height (mm); 0 reads it from the G-code.
Example
use Libraries.Fabrication.Printing.Bambu.BambuPackager
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
packer:SetLayerHeight(0.16)
text archive = packer:Pack("Outputs/cube.gcode")
SetNozzleDiameter(number diameter)
The nozzle diameter (mm) recorded in the archive.
Parameters
diameternumber: The diameter (mm).
Example
use Libraries.Fabrication.Printing.Bambu.BambuPackager
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
packer:SetNozzleDiameter(0.4)
text archive = packer:Pack("Outputs/cube.gcode")
SetPrinterModelId(text id)
printer_model_id: P2S = N7, A1 = N2S, A1 mini = N1, P1S = C12, X1C = BL-P001.
Parameters
idtext: The printer model ID.
Example
use Libraries.Fabrication.Printing.Bambu.BambuPackager
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
packer:SetPrinterModelId("N7") // a P2S
text archive = packer:Pack("Outputs/cube.gcode")
SetReportProgress(boolean report)
Whether Pack prints a timed line after each step (off by default). If a run seems stuck, the step after the last line printed is the slow one.
Parameters
reportboolean: True to print a line per step.
Example
use Libraries.Fabrication.Printing.Bambu.BambuPackager
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
packer:SetReportProgress(true)
text archive = packer:Pack("Outputs/cube.gcode")
SetSettingsTemplate(text path)
A project_settings JSON file, or a .gcode.3mf exported by Bambu Studio.
Parameters
pathtext: The JSON file or the .gcode.3mf.
Example
use Libraries.Fabrication.Printing.Bambu.BambuPackager
BambuPackager packer
packer:SetSettingsTemplate("Templates/bambu-p2s/p2s_project_settings.json")
text archive = packer:Pack("Outputs/cube.gcode")
SetSettingsText(text json)
The project_settings JSON itself, already filled in (for example by BambuSettingsMap from a profile). When set, Pack uses it instead of reading SetSettingsTemplate's file, and only changes the values it controls itself on top of it. "" goes back to the file.
Parameters
jsontext: The settings as JSON text; "" goes back to SetSettingsTemplate's file.
Example
use Libraries.Fabrication.Profiles.ProfileManager
use Libraries.Fabrication.Printing.Bambu.BambuSettingsMap
use Libraries.Fabrication.Printing.Bambu.BambuPackager
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
BambuSettingsMap map
BambuPackager packer
packer:SetSettingsText(map:FilledTemplate(profiles:Require("bambu-p2s"), "Templates/bambu-p2s/p2s_project_settings.json"))
text archive = packer:Pack("Outputs/cube.gcode")