Skip to content
Sathish111jPublic

About

Command-line slicing with Bambu Studio and LAN control of Bambu Lab printers (A1 mini and others), linked with the desktop app

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

bambu-cli

License: MIT Python 3.10+ macOS

Command-line slicing with Bambu Studio and LAN control of Bambu Lab printers — built for the A1 mini, works with any Bambu printer profile. It drives the Bambu Studio you already have installed and shares projects and presets with the desktop app, so you can script a job, look at it in the app, tweak it, and print it.

Made for AI coding agents too. Any AI tool that can use a terminal — Claude Code, OpenAI Codex, Cursor, Gemini CLI and others — gets direct access to Bambu Studio through this CLI. Just ask in plain words — "slice this bracket in PETG, stronger walls, two copies, and show it to me in Bambu Studio" — and the agent runs the commands, opens the result in the app for you to check, and can send it to the printer when you say so. See Using with AI agents.

bambu slice model.stl --filament "PETG HF" --process "0.16mm Optimal" --copies 2
bambu project a.stl b.stl --filament "PLA Basic" --filament "PLA Basic" \
      --color "#FFFFFF" --color "#FF0000" --obj 2:filament=2 --open   # two colours, opens in the app
bambu print model.gcode.3mf          # upload + start (asks first)
bambu status --watch

Not affiliated with Bambu Lab. "Bambu Lab" and "Bambu Studio" are trademarks of their owner. This tool calls the Bambu Studio application installed on your Mac; it does not include or modify it.

Features

  • Slice STL / 3MF / STEP / OBJ into printer-ready .gcode.3mf files with time, filament and a preview.
  • Every setting from the app's tabs (~480) via --set key=value; search 2,300+ presets.
  • Per-object control: a filament/colour per object, per-object settings, exact placement, mirror, X/Y/Z rotation, multiple plates, merge, skip — or a whole job in one JSON layout file.
  • Works with the desktop app: open results in Bambu Studio, use and create presets that appear in its dropdowns, and slice projects you edited there.
  • Printer control over LAN: status, print, pause/resume/stop, light, speed, temperatures, files, camera.
  • AI-agent friendly: --json output, clear error messages, JSON layout files, and confirmation before anything touches the printer.

Using with AI agents

bambu-cli turns Bambu Studio into something an AI assistant can operate from the terminal. Install it, open your AI tool in a folder with your models, and talk to it:

You say The agent runs (roughly)
"Will this fit on my A1 mini?" bambu model-info part.stl
"Slice it in PETG with 4 walls and 25% gyroid infill" bambu slice part.stl --filament "PETG HF" --set wall_loops=4 --set sparse_infill_density=25% --set sparse_infill_pattern=gyroid
"Make the logo white and the base black" bambu project base.stl logo.stl --filament "PLA Basic" --filament "PLA Basic" --color "#000000" --color "#FFFFFF" --obj 2:filament=2 --open
"Show me in Bambu Studio" bambu open part.3mf (you see and can edit it in the app)
"How long will it take and how much filament?" bambu --json info part.gcode.3mf
"Save these settings as my 'Strong PETG' preset" bambu preset save process "Strong PETG" --based-on "0.20mm Standard @BBL A1M" --set wall_loops=4
"Print it" bambu print part.gcode.3mf — asks you to confirm first

The loop that works best: the agent prepares → you look in Bambu Studio and adjust → you save → the agent slices and prints. Painting supports or seams, cutting and text stay in the app; the agent picks up your saved project with those edits intact.

For agents: read AGENTS.md — it lists the commands, the --json output, the layout-file format and the safety rules (never start a print or send G-code without the user's explicit OK).

Requirements

  • macOS with Bambu Studio installed in /Applications (tested with 2.9.2)
  • Python 3.10+ and uv (or pip)
  • For printer commands: a Bambu printer on the same network with LAN mode enabled (see below)

Install

uv tool install git+https://github.com/Sathish111j/bambu-cli
bambu --help

or from a clone: git clone https://github.com/Sathish111j/bambu-cli && cd bambu-cli && uv tool install -e .

Quick start

bambu model-info part.stl                    # size, fits the bed?, watertight?
bambu slice part.stl                         # uses the printer/filament/quality selected in the app
bambu info part.gcode.3mf                    # print time, grams, layers
bambu settings process infill                # find setting names
bambu slice part.stl --set sparse_infill_density=25% --set wall_loops=3 --open

How the app and the CLI work together

Bambu Studio has no remote-control API, so they share files:

Shared thing CLI → app App → CLI
Projects (.3mf) bambu project … --open builds a project and opens it in the app Edit/paint in the app, File → Save, then bambu slice / bambu print the saved .3mf — its settings are used
User presets bambu preset save → appears in the app's dropdowns (restart the app if it's open) Presets you save in the app are usable by name: --process "My preset"
Current selection — With no options, the CLI uses the printer / filament / quality selected in the app

Settings priority: explicit options → settings saved in a .3mf project → app's current selection → A1 mini defaults.

Typical flow: CLI builds the project → you check and tweak it in Bambu Studio → save → bambu print project.3mf (or press Print in the app — both work).

Commands

Slicing

Command What it does
bambu slice FILES… STL / 3MF / STEP / OBJ → printable .gcode.3mf + preview PNG + time & grams
bambu project FILES… Same options, but builds an unsliced project to open/edit in the app
bambu open FILE Open any model / project / sliced file in Bambu Studio
bambu info FILE.gcode.3mf Print time, filament, layers, plates
bambu preview FILE.gcode.3mf Save the plate preview image
bambu profiles machine|process|filament [words] [--printer "A1 mini"] Search the 2,300+ presets
bambu settings process [words] Show setting names + values (to use with --set)
bambu preset list / show / save / delete User presets shared with the app
bambu project-set PROJECT.3mf --set … --obj … Change global or per-object settings of a saved project without re-arranging it (e.g. turn supports on after arranging)
bambu app App's current selection, whether it's running, preset counts

Slice/project options: --printer, --process, --filament, --plate-type textured|smooth|cool|engineering|supertack, --set KEY=VALUE (repeatable), --copies N, --scale F, --rotate DEG, --no-orient, --no-arrange, --name, -o DIR, --open, --project-settings, --app-settings, --no-app-defaults. Add --json before the command for machine-readable output.

Per-object control, colours, plates

Objects are numbered in the order you give the models (1, 2, 3 …).

Goal Example
Multi-colour — one filament/colour per object (AMS lite: up to 4) bambu slice a.stl b.stl --filament "PLA Basic" --filament "PLA Basic" --color "#FFFFFF" --color "#FF0000" --obj 2:filament=2
Per-object settings --obj "2:sparse_infill_density=100%;wall_loops=5" (any print setting; copies of model 2 get it too)
Exact position (object centre on the bed, mm; A1 mini bed is 180 × 180) --obj "1:x=40;y=40" --obj "2:x=130;y=130"
Mirror / rotate --mirror x (all) or --obj 2:mirror=x; --rotate-x 90, --rotate-y 45, --rotate 30 (Z)
Multiple plates --obj 3:plate=2 --obj 4:plate=2 (plates with no x/y are auto-arranged)
Merge models into one multi-part object --merge
Skip objects when slicing a project bambu slice project.3mf --skip 2,3
Model info (size, fits the A1 mini?, volume, triangles, watertight) bambu model-info part.stl
Export STL bambu export-stl project.3mf -o out (merged) or --separate (one per object)

Per-object filaments and settings keep auto-orient and auto-arrange — use them on hundreds of parts and Bambu still packs them over as many plates as needed (the tool arranges, writes the per-object options into the project, and with several colours arranges once more so the prime tower gets room). Exact x/y and plate numbers switch to fixed placement instead: on one plate give x/y for every object or for none. Mirror, X/Y rotation and per-object options need STL/OBJ models.

Change a saved project (keeps the layout): bambu project-set car.3mf --set enable_support=1 --obj "3:filament=2;wall_loops=4" — edits in place, or -o new.3mf. Objects are numbered in project order. With 2+ filaments the prime tower is placed automatically in a free corner (override with --set wipe_tower_x=… --set wipe_tower_y=…).

Layout file — describe a whole job in JSON (bambu slice --layout job.json or bambu project --layout job.json --open):

{
  "filaments": [{"preset": "PLA Basic", "color": "#FFFFFF"}, {"preset": "PLA Basic", "color": "#F72323"}],
  "objects": [
    {"model": "cube.stl", "x": 50, "y": 90, "filament": 1},
    {"model": "cube.stl", "x": 130, "y": 90, "filament": 2, "mirror": "x",
     "settings": {"sparse_infill_density": "100%", "wall_loops": 4}},
    {"model": "cube.stl", "plate": 2, "copies": 2, "filament": 2}
  ]
}

See examples/layout-example.json. Model paths are relative to the layout file.

Troubleshooting: BAMBU_CLI_DEBUG=1 keeps the engine's inputs, command and log; BAMBU_CLI_TIMEOUT (default 900 s) stops a stuck run.

Printer (LAN mode — based on the community-documented protocol, not yet verified on hardware)

Command What it does
bambu printer add --ip IP --serial SN --code CODE Save the printer (details on its screen; stored in ~/.config/bambu-cli/printers.json, mode 600)
bambu status [--watch] [--raw] State, progress, layer, time left, temperatures, fan, errors
bambu print FILE [--plate N] [--no-level] [--timelapse] [--ams] [-y] Slice if needed → upload → start. Asks for confirmation
bambu pause / resume / stop Control the running print (stop asks first)
bambu light on|off, bambu speed silent|standard|sport|ludicrous
bambu temp --nozzle C --bed C Set target temperatures (0 = off)
bambu upload FILE, bambu files, bambu delete NAME Printer storage over FTPS
bambu snapshot [-o photo.jpg] Camera photo
bambu gcode "G28", bambu raw '{"print":{"command":"pause"}}' Advanced (ask first)

Printer setup: on the printer enable LAN Only Mode and Developer Mode (required since 2025 for third-party local control; the Bambu Handy cloud features stop working in this mode). Connect it to 2.4 GHz Wi-Fi. If the Mac firewall is on, allow Bambu Studio incoming connections.

App option → CLI setting

Every option on the app's settings tabs is a named setting; bambu settings process <word> finds it.

App (Prepare → settings) CLI key A1 mini default
Quality → Layer height layer_height 0.2
Quality → First layer height initial_layer_print_height 0.2
Quality → Line width line_width 0.42
Quality → Seam position seam_position (aligned/nearest/back/random) aligned
Quality → Ironing ironing_type (no ironing/top/topmost/solid) no ironing
Strength → Wall loops wall_loops 2
Strength → Top / bottom shell layers top_shell_layers / bottom_shell_layers 5 / 3
Strength → Sparse infill density sparse_infill_density (e.g. 25%) 15%
Strength → Infill pattern sparse_infill_pattern (grid/gyroid/cubic/…) grid
Speed → Outer / inner wall outer_wall_speed / inner_wall_speed 200 / 300
Speed → Sparse infill / travel sparse_infill_speed / travel_speed 270 / 700
Support → Enable support enable_support (0/1) 0
Support → Type support_type (normal(auto)/tree(auto)/…) tree(auto)
Support → Threshold angle support_threshold_angle 30
Others → Brim width brim_width 5
Others → Raft layers raft_layers 0
Others → Spiral vase spiral_mode (0/1) 0
Others → Fuzzy skin fuzzy_skin (none/external/all) none
Others → Prime tower enable_prime_tower (0/1) 1
Filament → Nozzle temperature nozzle_temperature 220 (PLA Basic)
Filament → Bed temp (textured plate) textured_plate_temp 65
Filament → Max fan speed fan_max_speed 80
Filament → Flow ratio filament_flow_ratio 0.98
Filament → Max volumetric speed filament_max_volumetric_speed 21

App-only (no CLI): support/seam/colour painting, cut, text/emboss, mesh boolean, modifier meshes, height-range modifiers (Bambu's engine crashes on them), the layer-by-layer preview, calibration wizards, firmware updates. Do these in the app, save the project, and the CLI will slice/print it with those edits intact.

Troubleshooting

Problem Fix
Bambu Studio not found Install it in /Applications, or set BAMBU_STUDIO_APP=/path/to/BambuStudio.app
A slice seems stuck Runs stop after BAMBU_CLI_TIMEOUT seconds (default 900). Re-run with BAMBU_CLI_DEBUG=1 to keep the engine's inputs, command and log
Found G-code outside of the printable area with several colours Move the prime tower: --set wipe_tower_x=120 --set wipe_tower_y=20
New preset doesn't show in the app Restart Bambu Studio (it reads presets at start-up)
Files open in a new Bambu Studio window Turn on Preferences → General → Single instance in Bambu Studio
Printer commands time out Check the IP, LAN Only + Developer Mode, same network, and the 8-digit access code

Development

uv venv && uv pip install -e ".[dev]"
uv run pytest -q            # slicing tests run when Bambu Studio is installed, otherwise they skip
uv run ruff check src tests && uv run mypy src --ignore-missing-imports

See CONTRIBUTING.md and the changelog.

License

MIT

Known Bambu Studio CLI quirks handled

  • Output must be a bare file name with the working dir = output dir (else "Unable to open … .tmp").
  • Without curr_bed_type the CLI assumes a Cool Plate and rejects PETG/ABS → default textured.
  • --repetitions is rejected and --clone-objects writes broken XML → copies are made by loading the model N times.
  • Exported projects copy every global setting onto each object with unescaped quotes → clean_project() removes the duplicates (so objects follow the app's global settings), keeps real per-object overrides, and escapes the rest.
  • The exporter shortens AMS-drying lists, so the app showed the filament preset as modified (*) → restored.
  • Assemble-list positions offset the mesh's own coordinates and copies in one entry accumulate → each object gets its own entry, with the offset computed from its bounding box.
  • Bambu's default prime-tower spot (back-left) runs off the A1 mini bed → moved to a free corner per plate.
  • A killed engine run makes macOS show an invisible "reopen windows?" alert that hangs every later run → the tool turns off window restoration for Bambu Studio (ApplePersistenceIgnoreState).

About

Command-line slicing with Bambu Studio and LAN control of Bambu Lab printers (A1 mini and others), linked with the desktop app

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages