Slice STLs with Bambu Studio's command-line slicer for print time and grams, or to build a one-plate project (.3mf) to open and print. Use when someone asks "how long will this take to print", "how many grams", "slice this", "put these parts on one plate", "will it fit on the bed", or writes a slice.sh.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Is that skill safe to install?
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
Are you the author of Bambu Cli Slicing?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/alexnodeland-bambu-cli-slicing)
---
name: bambu-cli-slicing
description: Slice STLs with Bambu Studio's command-line slicer for print time and grams, or to build a one-plate project (.3mf) to open and print. Use when someone asks "how long will this take to print", "how many grams", "slice this", "put these parts on one plate", "will it fit on the bed", or writes a slice.sh.
---
# Slicing with Bambu Studio's command-line slicer
The CLI is the app's own slicer without a window: `/Applications/BambuStudio.app/Contents/MacOS/BambuStudio`.
It never touches the app's window or the printer, so it is safe to run while a print is going. Given presets
flattened as below, it gives the app's numbers: on the 2026-12-01 PCIe test plate, 1h26m49s and 56.50 g, where
the app's Send dialog said 1h26min48s and 56.50 g.
## 1. Flatten the presets
The CLI takes presets as complete JSON files. The app's system presets are pieces: each `inherits` from
another, and many `include` templates (the X2D's start G-code, the per-variant filament arrays). They live in
`~/Library/Application Support/BambuStudio/system/BBL/{machine,process,filament}/`. Flatten them with the
plugin's script:
```sh
P="${CLAUDE_PLUGIN_ROOT}/scripts/bambu_presets.py"
python3 -I "$P" --list process --machine "Bambu Lab X2D 0.4 nozzle" # names the app offers
python3 -I "$P" --list filament --machine "Bambu Lab X2D 0.4 nozzle" --match petg
python3 -I "$P" --machine "Bambu Lab X2D 0.4 nozzle" --process "0.24mm Standard @BBL X2D" \
--filament "Bambu PLA Basic @BBL X2D 0.4 nozzle" --out presets/stock
python3 -I "$P" --machine ... --process ... --filament ... --out presets/tuned \
--set process.curr_bed_type="Textured PEI Plate" --set process.brim_type=outer_only
```
- It writes `machine.json`, `process.json`, `filament.json` (`filament-1.json`, ... for several) and
`SOURCE.json`: the profile folder, its version, the Bambu Studio version and the overrides. Keep
`SOURCE.json` beside the numbers it produced.
- Read its warnings. A process or filament "not made for" the machine (a 0.2 mm nozzle process on a 0.4
nozzle) slices anyway, and wrongly.
- `--set KIND.key=VALUE`: KIND is `machine`, `process`, `filament` (all) or `filament2` (one). Text over a
list sets every entry; a JSON list sets them one by one. Retraction differs per extruder variant
(`["0.4","0.4","0.4","3","3","3"]`), so change it with a JSON list, never a broadcast.
- `--show filament "<name>" nozzle_temperature hot_plate_temp` prints a flattened preset's keys.
- Always slice for the plate that is fitted (`process.curr_bed_type`). Without it the CLI uses the Cool
Plate, and PLA gets a 35 °C bed. See `materials-and-plates`.
## 2. Slice
Run each slice inside its own output folder, with absolute paths:
```sh
BS=/Applications/BambuStudio.app/Contents/MacOS/BambuStudio
X="$PWD/presets/tuned"
dir="$PWD/out/slice/base"; mkdir -p "$dir"
(cd "$dir" && "$BS" --debug 1 --slice 0 --arrange 1 \
--load-settings "$X/machine.json;$X/process.json" --load-filaments "$X/filament.json" \
--outputdir "$dir" "$PWD/out/base.stl" > log.txt 2>&1)
```
| Option | What it does |
|--------|--------------|
| `--slice 0` | Slice every plate. With loose STLs, `--slice 1` is reset to 0 anyway. |
| `--arrange 1` / `0` | Let it place the parts / keep each STL's own XY, which are bed coordinates (0,0 is a bed corner). |
| `--orient 0` | Keep the part as modelled. Orient it in the build instead (`design-for-fdm`). |
| `--load-filament-ids "1,2"` | Which filament each object uses, in load order. |
| `--export-3mf name.3mf` | Also write a project to open in the app. Then do `keep-project-settings`. |
| `--debug 1` | Errors only in the log; 3 for the steps, 5 for everything. |
## 3. Read result.json
`result.json` appears in the folder the CLI was run from.
```sh
python3 -I -c '
import json, sys
r = json.load(open(sys.argv[1]))
assert r["return_code"] == 0, r["error_string"]
for p in r["sliced_plates"]:
g = sum(f["total_used_g"] for f in p["filaments"])
print("plate %d: %.2f h model, %.2f h total, %.1f g %s" % (p["id"], p["main_predication"] / 3600,
p["total_predication"] / 3600, g, p.get("warning_message", "")))
' "$dir/result.json"
```
- `total_predication` is the G-code header's "total estimated time", start sequence included (about 5
minutes on the X2D). It is the time the app's Send dialog and Device tab show. Quote this one.
- `main_predication` is the header's "model printing time", without the start sequence.
- `filaments[].total_used_g` summed is the plate's grams.
- More than one entry in `sliced_plates` means the parts spilled onto a second plate.
- The G-code's third line says the same in words: `head -3 plate_1.gcode`.
## Plate layout: several parts on one plate
Lay the parts out yourself, in bed coordinates, in the build (`freecad-build`). Then slice with
`--arrange 0`, so the plate is what you checked. Precedent: the PCIe box test plate put two U-shaped rim
halves on the left of a 256 mm bed and the small coupons in a column on the right.
1. Place each part at its bed position, flat on the bed (ZMin = 0).
2. Check in the build: every part inside the bed; the closest pair at least the gap apart
(`a.distToShape(b)[0]` over every pair). Make it a build check, so a parameter change can't break it.
3. With a brim, keep at least the brim width plus 2 mm to the bed edge, and twice the brim width between
parts if they should have separate brims. The PCIe test plate sat 3 mm from the edge with a 5 mm brim: its
first-layer extrusion starts at x = 0.229, so the slicer clipped the brim at the bed edge.
4. A ring too big for the plate beside the other parts can be cut into U-shaped halves. Each half still tests
the fit across the full width.
5. Check the printer's no-go zones in `machine.json`: `bed_exclude_area` (empty on the X2D) and
`extruder_printable_area`. On the X2D the auxiliary (right) nozzle can't reach x < 20.5 mm.
6. Slice and assert `len(sliced_plates) == 1`.
## Traps
- **The cwd trap.** The CLI writes `result.json` into its working directory, even for `--help`. Run it in
a subshell that `cd`s into the output folder, never from a repository root.
- **`--outputdir` must be absolute with `--export-3mf`.** With `--outputdir .`, the log says "Project
exported to ./name.3mf" and the exit code is 0, but neither the 3MF nor `result.json` exists afterwards
(found 2026-12-01). Check that both files exist.
- **Exit 0 is not success.** Check `result.json` exists and its `return_code` is 0.
- **Unflattened system files** (straight from the `system/BBL` folder): exit 0 and `return_code` 0, but the
wrong settings: 0.20 mm layers for a 0.24 mm process, and a generic start G-code.
- **A flattener that ignores `include`** slices with a generic start G-code. On the X2D that is 577
characters instead of its 14,908-character start sequence. On a 23 g coupon the total time read 33m38s
instead of 38m21s; on the PCIe test plate, 1h22m09s instead of the app's 1h26m48s. Copies of `x2d_presets.py` in older project folders have this gap: re-flatten with
`bambu_presets.py`.
- **A 3MF with no project block** (a plain mesh 3MF from another tool) segfaults the CLI (exit 139). Export
STLs and slice those.
- **"No valid nozzle found"** when re-slicing an X2D 3MF that the CLI exported itself. Slice the STLs again
with `--load-settings` and `--load-filaments`.
- **Never print the CLI's G-code.** Open the 3MF in the app and slice it there (`print-a-plate`).
- **A CLI-exported 3MF opens on stock settings** unless it names its presets: `keep-project-settings`.
Put the time and grams in the project README's print table (`maker-project`).