# How to Integrate Text-to-CAD with Bambu Labs Printers for Direct Print Jobs

> Integrate text-to-CAD with Bambu Labs printers for direct LAN printing. Upload G-code via FTPS and control printers over MQTT with this Python workflow. No cloud needed.

- Repository: [earthtojake/text-to-cad](https://github.com/earthtojake/text-to-cad)
- Tags: how-to-guide
- Published: 2026-07-29

---

**The earthtojake/text-to-cad repository provides a complete Python-based workflow to configure, upload G-code via FTPS, and control Bambu Labs printers over MQTT for direct LAN printing without cloud dependencies.**

The text-to-cad project ships with a self-contained Bambu Labs integration located in [`skills/bambu-labs/scripts/bambu_lan_print.py`](https://github.com/earthtojake/text-to-cad/blob/main/skills/bambu-labs/scripts/bambu_lan_print.py). By leveraging local network protocols—specifically implicit FTPS for file transfers and MQTT for real-time command publishing—you can integrate with Bambu Labs printers for direct print jobs using either command-line interfaces or programmatic Python APIs.

## Configure Printer Access and Discover Serial Numbers

The workflow begins with a JSON configuration file named [`bambu-printers.json`](https://github.com/earthtojake/text-to-cad/blob/main/bambu-printers.json) that persists host addresses, access codes, printer models, and cached serial numbers. The helper functions `load_config`, `save_config`, and `apply_printer_config` manage reading and updating this file.

Before the first print job, you must obtain the printer's serial number, which is embedded in its TLS certificate. The `discover_printer_serial` function opens a TLS socket to the printer, extracts the certificate, and parses the **Common Name** field to obtain the serial. This value is then cached back into the JSON configuration for subsequent operations, eliminating the need for repeated certificate inspection.

```bash
python -m skills.bambu-labs.scripts.bambu_lan_print \
  config set \
  --printer my-printer \
  --host 192.168.1.42 \
  --access-code 12345678 \
  --model P1S \
  --fetch-serial

```

The `--fetch-serial` flag triggers the TLS discovery logic and stores the result in your local config.

## Upload G-code Files Using Implicit FTPS

File transfers utilize the `upload_ftps` function, which establishes an implicit TLS connection (`ImplicitFTP_TLS`) to the printer's FTP server. This implementation handles TLS context creation, remote directory creation under the `cache/` path, and robust `STOR` operations with timeout tolerance.

For standard G-code workflows, the system uploads plain `.gcode` files to paths formatted as `cache/<filename>.gcode`. The `build_send_plan` function constructs the complete execution plan, determining the remote destination and payload structure before calling `upload_ftps` at line 338–360 of the source file.

## Control Prints via MQTT Command Publishing

After uploading files, the `publish_mqtt` function handles printer command dispatch. It builds a CONNECT packet, optionally subscribes to status topics, and publishes JSON payloads to `device/<serial>/request`.

Supported commands include:
- **`gcode_file`** – Notifies the printer of a new G-code upload
- **`project_file`** – Handles `.gcode.3mf` project uploads
- **`start`** and **`stop`** – Control print job execution

The function optionally waits for `PUBACK` acknowledgments or collects status reports from the `device/<serial>/report` topic, enabling synchronous confirmation of print starts.

## Package Models with Bambox for 3MF Support

For printers requiring the Bambu Box format, the helper can wrap plain G-code into `.gcode.3mf` packages using the external `bambox` CLI. The `build_bambox_pack_command` assembles the necessary shell command (e.g., `bambox pack model.gcode -o model.gcode.3mf -m p1s --nozzle-diameter 0.4 -f PLA`), which is then executed via `run_checked_command`.

When using Bambox packaging, the MQTT payload switches to `project_file` type, and plate information is extracted from the resulting 3MF package using `inspect_sliced_3mf` before publishing the start command.

## End-to-End CLI Workflows

Send a plain G-code file and immediately start the print:

```bash
python -m skills.bambu-labs.scripts.bambu_lan_print \
  send \
  --printer my-printer \
  --gcode /path/to/model.gcode \
  --action upload-start \
  --confirm-start-print \
  --execute

```

This executes the full pipeline: `apply_printer_config` resolves credentials, `build_plain_send_plan` determines the remote path, `upload_ftps` transfers the file, and `publish_mqtt` dispatches the start command with the `gcode_file` parameter.

Use Bambox packaging for advanced filament and profile control:

```bash
python -m skills.bambu-labs.scripts.bambu_lan_print \
  send \
  --printer my-printer \
  --gcode /path/to/model.gcode \
  --handoff bambox-project \
  --bambox-profile p1s-0.4 \
  --filament PLA \
  --action upload-start \
  --confirm-start-print \
  --execute

```

Query real-time printer status by subscribing to MQTT report topics:

```bash
python -m skills.bambu-labs.scripts.bambu_lan_print \
  status \
  --printer my-printer \
  --wait-seconds 5

```

The status command uses `ensure_printer_serial` to resolve or discover the serial number, then subscribes to `device/<serial>/report` via MQTT to collect and display printer state information.

## Summary

- **Configuration persistence** uses [`bambu-printers.json`](https://github.com/earthtojake/text-to-cad/blob/main/bambu-printers.json) managed by `load_config` and `save_config` functions to store host, access code, and cached serial numbers.
- **Serial discovery** extracts the printer identifier from TLS certificate Common Names via `discover_printer_serial`.
- **File transfer** relies on `upload_ftps` with implicit TLS to place G-code files in the printer's `cache/` directory.
- **Command and control** uses `publish_mqtt` to send structured JSON commands to `device/<serial>/request` topics, supporting both immediate execution and status monitoring.
- **Advanced packaging** leverages `build_bambox_pack_command` to create `.gcode.3mf` files when the target printer requires project-based workflows.

## Frequently Asked Questions

### Do I need cloud access to print using this integration?

No. The text-to-cad Bambu Labs integration operates entirely over your local area network using FTPS for file transfers and MQTT for printer commands, bypassing Bambu Lab's cloud infrastructure entirely.

### How does the system obtain the printer serial number?

The `discover_printer_serial` function connects to the printer's TLS port, retrieves the TLS certificate, and parses the Common Name field to extract the serial number. This value is cached in [`bambu-printers.json`](https://github.com/earthtojake/text-to-cad/blob/main/bambu-printers.json) to avoid repeated network operations.

### Can I programmatically integrate this without using the CLI?

Yes. The [`bambu_lan_print.py`](https://github.com/earthtojake/text-to-cad/blob/main/bambu_lan_print.py) module exposes Python functions including `apply_printer_config`, `build_send_plan`, `upload_ftps`, and `publish_mqtt` that you can import and call directly from your own scripts to integrate with Bambu Labs printers for direct print jobs.

### What file formats does the system support?

The workflow supports plain `.gcode` files for direct printing and `.gcode.3mf` project files when using the optional Bambox packaging path. The [`gcode_tool.py`](https://github.com/earthtojake/text-to-cad/blob/main/gcode_tool.py) helper additionally validates G-code and detects compatibility with Bambu Studio executables.