📚 Encyclopedia

3D Printing & CAD · updated 2026-10-13

Slicing from the command line with Bambu Studio (flatpak), including two-color prints

bambubambu-studioslicercliflatpak3mfmulticolorx2d

Bambu Studio can slice headlessly, which lets a script turn STLs into a ready-to-print .gcode.3mf for a Bambu printer (here Justin's Bambu Lab X2D, two nozzles). The CLI is poorly documented and fails in confusing ways; these are the rules that made it work with the flatpak build (com.bambulab.BambuStudio, 2.8.x).

Basic recipe

Two colors (or more)

The CLI's filament count follows filament_colour, and system filament presets carry no filament_colour, so every part collapses onto filament 1: no tool changes in the G-code and only one filament in the exported project. (This was first misdiagnosed as "the CLI ignores per-part extruders".) Fix: pass flattened filament JSONs that each set filament_colour (one per color). Then either works: - Per-part assignment: --assemble --load-filament-ids "1,2,1" with the part STLs in order; they become one "Assembly" object with per-part filaments. - Height-based color changes on one STL: --load-custom-gcodes changes.json with json {"mode":"MultiAsSingle","gcodes":[{"print_z":2.2,"type":"ToolChange","extruder":2,"color":"#FFFFFF","extra":""}]} type is a string enum; print_z is the first layer printed in the new filament.

Example: a 101.6 x 101.6 x 38.1 mm Paycom "p" logo with 2 mm green caps and a white core sliced to 1h32m, about 20 g green + 69 g white, two filament changes with a prime tower, both filaments on one nozzle (the CLI left filament_map at 1,1; forcing one color per X2D nozzle was not attempted). Without an AMS, the same print works by pausing at the layer heights and swapping filament by hand.

3MF pitfalls

Generating projects that slice without help (3d site and orrery, 2026-10)

Generated Bambu projects for the X2D (3d.jhampton.io /create downloads and the orrery kit) needed more than flattened presets. These were found the hard way. - The CLI does not resolve inherits/include, and this build has no *_full presets. Leaf presets saved by the CLI are padded with program defaults: start G-code of 46 characters instead of 14,848, no prime tower, infill density 0. Shipping such CLI-saved settings and calling them "genuine" was wrong by about 100 settings. Diff a few load-bearing values (start G-code length, a density, a toggle) against the source preset before claiming fidelity. - Segfault cause, precisely: a Bambu project with no printer profile, meaning no project_settings.config or one without printer_settings_id. That is what the CLI writes itself when --load-settings is not passed. It does not crash on every Bambu project. - It leaves printer and window state blank, and slicing fails on each in turn: - extruder_nozzle_stats: [] gives "No valid nozzle found"; fill in Standard#1 per extruder. - A 4x4 flush_volumes_matrix gives "Flush volumes matrix do not match"; it needs filaments squared times extruders entries, plus flush_multiplier per extruder. - A prime tower at x = 15 on the X2D gives "Found G-code in unprintable area of multi-extruder printers" because nozzle 2 starts at x = 20.5; place it near (205, 205). - Error messages go to stderr unprefixed between log lines. Grep for lines not starting with [; otherwise a failure looks like it had no message. - With those fixed, generated two- and three-filament projects slice with one filament per X2D nozzle (three filaments need an AMS).

Generating settings data

tools/3d-bambu-x2d.py drives the CLI about 80 times to emit a base plus per-filament-type deltas (X2D 0.4 nozzle, "0.20mm Standard @BBL X2D", 1 to 3 filaments, ~380 KB JSON) that the browser merges into each download. Per-template overrides (enable_support: '1', brim_type: 'outer_only', wipe_tower_x/y, enable_prime_tower: 0) are merged in and listed in different_settings_to_system[0], which marks the project as modified from the system preset. See 3MF files and the Bambu Studio project layout.

More sandbox facts

Measured examples (X2D, 0.4, standard)

Flat two-color cat tag 2.3 g + 0.2 g, ~15 min; ball tag in PETG with supports 13 g + 1.8 g, ~50 min; Gridfinity 2x1x3 labeled bin 24.6 g, ~50 min; orrery kit on five plates 7 h 41 min, 232 g. Whether the GUI honors embedded overrides on open, and any real print, remain unverified.

Gotchas

See also

Linked from

Sources: home memory project_mower_wheel, dev memory paycom-logo-3d.md, justinahampton memory (3d-create-templates, verify-claims-against-source, freetime-orrery), tldr posts #1608, #1705, #1706, #1760