merge_multicolor_gcode
Merge separately-sliced gcode files into a single multi-tool gcode file, using a batched strategy to reduce tool changes for multi-color prints. Requires parts with non-overlapping XY footprints.
Instructions
Merge separately-sliced gcode files into one multi-tool gcode.
Uses a batched strategy that minimises tool changes for multi-color
prints. Parts with overlapping Z ranges are printed in tool order
within the overlap zone, then remaining layers continue above.
This is the key step between slicing individual parts and wrapping
as a Bambu 3MF. The merged gcode contains T0/T1/... tool change
commands that ``wrap_gcode_as_3mf`` converts to M620/M621 AMS
load sequences.
**Precondition:** Parts must be **XY-disjoint** (non-overlapping
footprints on the build plate). The batched merge prints each
tool's layers independently in the overlap zone — overlapping XY
regions will cause collisions.
Args:
parts: JSON array of part objects. Each must have:
- ``gcode_path``: Path to the sliced ``.gcode`` file.
- ``tool_index``: Tool number (0, 1, ...) for AMS mapping.
- ``name``: Human-readable name (e.g. ``"body_grey"``).
Example::
[
{"gcode_path": "/path/body.gcode", "tool_index": 0, "name": "body"},
{"gcode_path": "/path/qr.gcode", "tool_index": 1, "name": "qr_pads"}
]
output_path: Output file path. Defaults to a temp directory.
Returns a dict with ``output_path``, merge phases, layer count,
and estimated print time.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| parts | Yes | ||
| output_path | No |