merge_multicolor_gcode
Merge separately sliced g-code files into one multi-tool file, batching layers to reduce tool changes for multi-color 3D prints on XY-disjoint parts.
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.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"parts": "<parts>"
},
"name": "merge_multicolor_gcode"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| parts | Yes | 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 | No | Output file path. Defaults to a temp directory. Default: "". |