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

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. 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 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.

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:

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:

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:

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 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 to avoid repeated network operations.

Can I programmatically integrate this without using the CLI?

Yes. The 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 helper additionally validates G-code and detects compatibility with Bambu Studio executables.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →