Combines and nests multiple G-code files into a single output file, automatically arranging pieces within your machine's working area to minimise material waste. Useful when your CAM software (Fusion 360, FreeCAD, etc.) generates one file per part and you want to cut them all in one job.
Designed for Grbl and LinuxCNC machines. Handles standard G-code from common CAM tools.
Each input file is assumed to have its own origin at (0, 0, 0). gcoco:
- Parses each file to compute its XY bounding box
- Arranges all pieces within the specified working area using bin-packing (largest pieces first, minimising wasted space)
- If pieces don't all fit, splits them across multiple output files
- Writes combined output files with all coordinates translated to their assigned positions
Between pieces the tool lifts to a safe Z height, rapids to the next piece's position, then continues.
go install github.com/ashep/gcoco@latestOr build from source:
git clone https://github.com/ashep/gcoco
cd gcoco
go build -o gcoco .gcoco [flags] file1.gcode file2.gcode ...
| Flag | Default | Description |
|---|---|---|
--width |
required | Working area width in mm |
--height |
required | Working area height in mm |
--safe-z |
5 |
Z height for rapid moves between pieces (mm) |
--spacing |
1 |
Minimum gap between pieces (mm) |
--output-dir |
. |
Directory for output files |
gcoco --width 400 --height 300 --safe-z 5 --spacing 3 --output-dir ./out *.ncOutput:
Packing 4 piece(s) into 1 batch(es)...
Batch 1: 4 piece(s)
Front.nc -> X=0.00 Y=0.00
Back.nc -> X=0.00 Y=76.80
Left.nc -> X=141.00 Y=0.00
Right.nc -> X=141.00 Y=76.80
Done. Output written to ./out/
Output files are named combined_1.gcode, combined_2.gcode, etc. — one per batch.
Each combined file:
- Sets absolute mode (
G90) and mm units (G21) - Lifts to safe Z before the first piece and between pieces
- Returns to origin (
G0 X0 Y0) and ends withM2at the end
The following codes are stripped from input files and handled at the combined file level: G21, G90, G91, G28,
M2, M30.
Pieces are not rotated — they are placed in the same orientation as in the input files. If rotating a piece would allow for a better fit, you need to do that in your CAM software before running gcoco.
- Input files must use mm units (
G21) - Input files must use absolute coordinates (
G90) — the tool assumes this by default, matching standard CAM output - Compatible with Grbl and LinuxCNC flavoured G-code