--load-custom-gcodes
<json>Inject a JSON-described list of per-layer G-code events (tool changes, color changes, pauses, or raw G-code) into a specific plate of the model, fully replacing the entire custom G-code map the 3MF previously held for all plates.
Details
--load-custom-gcodes accepts a path to a JSON file that injects per-layer custom G-code events into the model before slicing. The CLI reads the file, deserializes it into an internal custom G-code event structure, and writes those events into the first loaded model's per-plate custom G-code map at the entry corresponding to the plate that will be sliced.
The assignment is a full replacement of the entire per-plate custom G-code map, not a merge and not a per-plate update. Because the newly built map contains only the one plate loaded from the JSON file, any custom G-code data that was already embedded in the 3MF for any plate -- including plates other than the target -- is completely discarded by this operation.
The JSON file must contain one required top-level key and one optional one. "gcodes" is required: it is an array of event objects, and a missing key causes the CLI to exit with a config-file error. "mode" is optional: when present it must be one of the strings "SingleExtruder", "MultiAsSingle", or "MultiExtruder"; when absent or unrecognised the mode is stored as Undef, which the slicer can infer from the event types later.
Each event object in "gcodes" requires four keys: "type" (a string), "print_z" (a float, in millimetres, marking the layer height at which the event fires), "extruder" (an integer, 1-based extruder index), and "color" (a string, can be empty). An optional "extra" string carries the raw G-code text when "type" is "Custom", or the pause message text when "type" is "PausePrint". Valid "type" values are "ColorChange", "PausePrint", "ToolChange", "Template", "Custom", and "Unknown". An unrecognised type string is silently stored as "Unknown" rather than causing a parse error.
When --slice targets a specific plate (a non-zero plate index), the loaded events are bound to that plate's zero-based index in the map. When slicing all plates (--slice 0), the events are bound to plate index 0.
If --skip-modified-gcodes is also present, it runs as a post-load pass that iterates every plate's event list and removes any event whose type is Custom. Non-Custom events (ToolChange, ColorChange, PausePrint, etc.) are left intact. If a JSON file loads only Custom-type events and --skip-modified-gcodes is set, all of them are stripped and no events survive into the slice.
Examples
{
"mode": "MultiExtruder",
"gcodes": [
{
"type": "ToolChange",
"print_z": 4.2,
"extruder": 2,
"color": ""
},
{
"type": "Custom",
"print_z": 12.0,
"extruder": 1,
"color": "",
"extra": "M600\n"
}
]
}Watch out for
- ▲ If the file path does not exist on disk at parse time, the CLI exits immediately with a file-not-found error before any slicing occurs. A syntactically valid path that points to malformed JSON or a JSON object missing the `"gcodes"` key causes a config-file error exit instead.
- ▲ The JSON replaces, not augments, whatever custom G-code data the model contains. Because the full per-plate custom G-code map is replaced with a single-entry map, custom G-codes embedded in the 3MF for every other plate are also cleared, not just those for the target plate.
- ▲ When slicing a non-BBL 3MF, any non-zero `--slice` value is silently reset to 0 before the plate-id lookup happens, so the events always land on plate index 0 in that case.
Sign up for free today
No credit card required. Connect unlimited printers and get production automation running in minutes.