BambuSettingsMap
Package: Libraries.Fabrication.Printing.Bambu · Inherits from: Libraries.Language.Object
The BambuSettingsMap class writes a slicer Profile's settings into a Bambu Studio project_settings template, under Bambu's own key names. Bambu Studio needs the complete set of about 580 settings in exactly the shape its version writes, so this never builds the file from scratch: it starts from a template that Bambu Studio exported for the same printer, nozzle and filament (see BambuProjectSettings) and changes only the keys listed in Apply. Keys the template doesn't have (another Bambu Studio version) are skipped and listed in the warnings. The printer runs the G-code inside the 3MF, not these settings. They are what Bambu Studio and the printer's screen show for the print, and the printer checks the nozzle, filament and plate against them, so they should describe what was actually sliced. To map another setting, add it to ProfileSchema and add one line to Apply.
Example Code
use Libraries.Fabrication.Profiles.ProfileManager
use Libraries.Fabrication.Profiles.Profile
use Libraries.Fabrication.Printing.Bambu.BambuSettingsMap
class Main
action Main
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
Profile profile = profiles:Require("bambu-p2s")
BambuSettingsMap map
// the settings that go inside the .gcode.3mf
text json = map:FilledTemplate(profile, profile:GetText("bambuSettingsTemplate"))
// or a standalone copy to look at, diff or import
map:WriteTemplate(profile, profile:GetText("bambuSettingsTemplate"), "Outputs/project_settings.json")
end
end
Actions
FilledTemplate(Libraries.Fabrication.Profiles.Profile profile, Libraries.System.File templateFile)
Like FilledTemplate(Profile, text), from a File.
Parameters
profileLibraries.Fabrication.Profiles.Profile: The profile to copy the settings from.templateFileLibraries.System.File: The template exported by Bambu Studio.
Returns
text: The filled project_settings JSON.
Example
use Libraries.System.File
use Libraries.Fabrication.Profiles.ProfileManager
use Libraries.Fabrication.Printing.Bambu.BambuSettingsMap
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
File file
file:SetPath("Templates/bambu-p2s/p2s_project_settings.json")
BambuSettingsMap map
text json = map:FilledTemplate(profiles:Require("bambu-p2s"), file)
FilledTemplate(Libraries.Fabrication.Profiles.Profile profile, text templatePath)
Reads the template (a project_settings JSON, or a .gcode.3mf exported by Bambu Studio), fills in the profile and returns the JSON text.
Parameters
profileLibraries.Fabrication.Profiles.Profile: The profile to copy the settings from.templatePathtext: The template exported by Bambu Studio.
Returns
text: The filled project_settings JSON.
Example
use Libraries.Fabrication.Profiles.ProfileManager
use Libraries.Fabrication.Printing.Bambu.BambuSettingsMap
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
BambuSettingsMap map
text json = map:FilledTemplate(profiles:Require("bambu-p2s"), "Templates/bambu-p2s/p2s_project_settings.json")
output map:GetFilledCount() + " settings filled in"
GetFilledCount()
How many keys the last FilledTemplate changed.
Returns
integer: How many keys the last FilledTemplate changed.
Example
use Libraries.Fabrication.Profiles.ProfileManager
use Libraries.Fabrication.Printing.Bambu.BambuSettingsMap
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
BambuSettingsMap map
text json = map:FilledTemplate(profiles:Require("bambu-p2s"), "Templates/bambu-p2s/p2s_project_settings.json")
output map:GetFilledCount() + " settings changed"
GetMissingKeys()
The keys the last FilledTemplate wanted but the template doesn't have.
Returns
Libraries.Containers.Array<text>: The keys the last FilledTemplate wanted but the template doesn't have.
Example
use Libraries.Containers.Array
use Libraries.Fabrication.Profiles.ProfileManager
use Libraries.Fabrication.Printing.Bambu.BambuSettingsMap
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
BambuSettingsMap map
text json = map:FilledTemplate(profiles:Require("bambu-p2s"), "Templates/bambu-p2s/p2s_project_settings.json")
Array<text> missing = map:GetMissingKeys()
output missing:GetSize() + " settings the template doesn't have"
GetWarnings()
Warnings from the last FilledTemplate (missing keys, a template for another nozzle or filament), as sentences.
Returns
Libraries.Containers.Array<text>: Warnings from the last FilledTemplate (missing keys, a template for another nozzle or filament), as sentences.
Example
use Libraries.Containers.Array
use Libraries.Fabrication.Profiles.ProfileManager
use Libraries.Fabrication.Printing.Bambu.BambuSettingsMap
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
BambuSettingsMap map
text json = map:FilledTemplate(profiles:Require("bambu-p2s"), "Templates/bambu-p2s/p2s_project_settings.json")
Array<text> warnings = map:GetWarnings()
integer i = 0
repeat while i < warnings:GetSize()
output "warning: " + warnings:Get(i)
i = i + 1
end
SetReportMissing(boolean toggle)
Whether keys missing from the template are listed as a warning (on by default).
Parameters
toggleboolean: True to list missing keys as a warning.
Example
use Libraries.Fabrication.Profiles.ProfileManager
use Libraries.Fabrication.Printing.Bambu.BambuSettingsMap
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
BambuSettingsMap map
map:SetReportMissing(false)
text json = map:FilledTemplate(profiles:Require("bambu-p2s"), "Templates/bambu-p2s/p2s_project_settings.json")
WriteTemplate(Libraries.Fabrication.Profiles.Profile profile, text templatePath, text outputPath)
Like FilledTemplate, and writes the result to outputPath. Returns outputPath.
Parameters
profileLibraries.Fabrication.Profiles.Profile: The profile to copy the settings from.templatePathtext: The template exported by Bambu Studio.outputPathtext: Where to write the filled JSON.
Returns
text: outputPath.
Example
use Libraries.Fabrication.Profiles.ProfileManager
use Libraries.Fabrication.Printing.Bambu.BambuSettingsMap
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
BambuSettingsMap map
text written = map:WriteTemplate(profiles:Require("bambu-p2s"), "Templates/bambu-p2s/p2s_project_settings.json", "Outputs/project_settings.json")