ProfileManager
Package: Libraries.Fabrication.Profiles · Inherits from: Libraries.Language.Object
The ProfileManager class keeps the slicer profiles and reads / writes them as JSON. The file is one object with a profile per key. A profile lists only the settings it changes; "inherits" names the profile it starts from. Keys starting with "_" are comments and are skipped. { "bambu-p2s": { "bedWidth": 256, "bedDepth": 256, ... }, "bambu-p2s-petg": { "inherits": "bambu-p2s", "filamentType": "PETG" } } Mistakes that make a file unusable (bad JSON, a value outside its range, a duplicate name, an inheritance loop) stop with a message naming the file and profile. Mistakes that can be skipped (an unknown or misspelled setting) are collected in GetWarnings.
Example Code
use Libraries.Containers.Array
use Libraries.Fabrication.Profiles.ProfileManager
use Libraries.Fabrication.Profiles.Profile
class Main
action Main
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
Array<text> warnings = profiles:GetWarnings()
integer i = 0
repeat while i < warnings:GetSize()
output "warning: " + warnings:Get(i)
i = i + 1
end
Profile p2s = profiles:Require("bambu-p2s")
end
end
Actions
Add(Libraries.Fabrication.Profiles.Profile profile)
Adds a profile and links it to its parent. Stops if the name is empty or taken.
Parameters
profileLibraries.Fabrication.Profiles.Profile: The profile; its name must be new.
Example
use Libraries.Fabrication.Profiles.ProfileManager
use Libraries.Fabrication.Profiles.Profile
ProfileManager profiles
Profile mine
mine:SetName("my-printer")
mine:SetNumber("bedWidth", 235)
profiles:Add(mine)
Derive(text parentName, text newName)
Makes a new profile that inherits from an existing one, and adds it.
Parameters
parentNametext: The profile to inherit from.newNametext: The new profile's name.
Returns
Libraries.Fabrication.Profiles.Profile: The new profile, already added.
Example
use Libraries.Fabrication.Profiles.ProfileManager
use Libraries.Fabrication.Profiles.Profile
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
Profile draft = profiles:Derive("ender3-v2", "ender3-v2-draft")
draft:SetNumber("layerHeight", 0.28)
Find(text name)
The profile with this name, or undefined.
Parameters
nametext: The profile's name.
Returns
Libraries.Fabrication.Profiles.Profile: The profile with this name, or undefined.
Example
use Libraries.Fabrication.Profiles.ProfileManager
use Libraries.Fabrication.Profiles.Profile
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
Profile maybe = profiles:Find("prusa-mk4")
if maybe = undefined
output "No such profile."
end
Get(integer index)
A profile by position, in the order they were loaded or added.
Parameters
indexinteger: The position, from 0 to GetSize() - 1.
Returns
Libraries.Fabrication.Profiles.Profile: The profile.
Example
use Libraries.Fabrication.Profiles.ProfileManager
use Libraries.Fabrication.Profiles.Profile
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
integer i = 0
repeat while i < profiles:GetSize()
Profile profile = profiles:Get(i)
output profile:GetName()
i = i + 1
end
GetSize()
The number of profiles loaded.
Returns
integer: The number of profiles.
Example
use Libraries.Fabrication.Profiles.ProfileManager
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
output profiles:GetSize() + " profiles"
GetWarnings()
Problems found while loading that didn't stop the load (unknown settings, empty profiles).
Returns
Libraries.Containers.Array<text>: Problems found while loading that didn't stop the load (unknown settings, empty profiles).
Example
use Libraries.Containers.Array
use Libraries.Fabrication.Profiles.ProfileManager
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
Array<text> warnings = profiles:GetWarnings()
integer i = 0
repeat while i < warnings:GetSize()
output "warning: " + warnings:Get(i)
i = i + 1
end
Include(text path)
Adds the profiles in the file to the ones already loaded. The file is read with JavaScriptObjectNotationTemplate (the reader that edits Bambu's settings) rather than JavaScriptObjectNotation, whose Read doesn't parse a nested object handed back as text.
Parameters
pathtext: The profiles JSON file.
Example
use Libraries.Fabrication.Profiles.ProfileManager
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
profiles:Include("Profiles/my-printers.json")
Load(text path)
Replaces the loaded profiles with the ones in the file.
Parameters
pathtext: The profiles JSON file.
Example
use Libraries.Fabrication.Profiles.ProfileManager
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
output profiles:GetSize() + " profiles loaded"
Remove(text name)
Removes the named profile. Profiles that inherited from it stop inheriting.
Parameters
nametext: The profile's name.
Example
use Libraries.Fabrication.Profiles.ProfileManager
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
profiles:Remove("ender3-v2-fine")
Require(text name)
The profile with this name; stops with an alert if there isn't one.
Parameters
nametext: The profile's name.
Returns
Libraries.Fabrication.Profiles.Profile: The profile.
Example
use Libraries.Fabrication.Profiles.ProfileManager
use Libraries.Fabrication.Profiles.Profile
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
Profile p2s = profiles:Require("bambu-p2s")
Save(text path)
Writes every profile, each with only the settings it sets itself.
Parameters
pathtext: Where to write the JSON.
Example
use Libraries.Fabrication.Profiles.ProfileManager
use Libraries.Fabrication.Profiles.Profile
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
Profile draft = profiles:Derive("ender3-v2", "ender3-v2-draft")
draft:SetNumber("layerHeight", 0.28)
profiles:Save("Profiles/profiles.json")
Save(text path, boolean flatten)
Writes every profile. With flatten = true each profile is written with every setting resolved (no "inherits"), which shows the complete set a slice will use.
Parameters
pathtext: Where to write the JSON.flattenboolean: True to write every setting of every profile.
Example
use Libraries.Fabrication.Profiles.ProfileManager
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
profiles:Save("Outputs/every-setting.json", true)
ValidateAll()
Checks every profile with Profile:Validate. Returns one sentence per problem, each naming its profile; an empty array means every profile is fine.
Returns
Libraries.Containers.Array<text>: One sentence per problem, each naming its profile; empty if every profile is fine.
Example
use Libraries.Containers.Array
use Libraries.Fabrication.Profiles.ProfileManager
ProfileManager profiles
profiles:Load("Profiles/profiles.json")
Array<text> problems = profiles:ValidateAll()
if problems:GetSize() = 0
output "Every profile is fine."
end