Skip to content

Proving the G-code

Outcome: taking a sliced file's claims one at a time and checking each against the file itself, with a small script that does the counting.

Check: every number from chapter 5's slice is re-derived below from plate_1.gcode, and the two sets agree — or the disagreement is named.

This is the chapter the guide exists for. Slicers are usually used on trust: press slice, read the summary, print. But the output is plain text. An hour's scepticism here and there teaches you what the summary numbers actually mean — and catches the day a wrong preset produces a confident, wrong file.

The lab's tool is orcaslicer-lab/check_gcode.py, a hundred lines of Python that read the file the way an auditor would. Full output: transcripts/t03-proving-gcode.txt.

Claim 1: the slicer and version

header: ; generated by OrcaSlicer 2.4.2

First line of the file. When a print misbehaves, this line says which slicer — and which release — wrote the instructions being followed.

Claim 2: 100 layers, three ways

The footer claims ; total layer number: 100. Check it twice more, independently:

  • Count the ;LAYER_CHANGE marker comments the slicer left at each new layer: 100.
  • Collect every Z height at which filament actually extrudes, and count the distinct heights: 100.

Three methods, one number. Marker comments alone could repeat or lie; extrusion heights are the printer's actual working levels. When all three agree, the layer structure of the file is not in doubt.

Claim 3: the filament total

The footer claims:

; filament used [mm] = 1341.47
; filament used [cm3] = 3.23
; total filament used [g] = 0.00

The checker reads every extrusion move, tracks absolute versus relative mode (M82/M83) and resets (G92 E0), and sums the moves two ways:

  • Net — forward minus retracted, the plastic that ends up in the part and its skirt: 1321.7 mm.
  • Gross — every forward push, including the re-push after each retraction: 1592.9 mm.

The footer's 1341.47 sits between them, about 1.5% above the net sum. That is the honest picture: the slicer's statistic is computed from its plan, the checker's from the emitted moves, and they agree to within a percent and a half. The moves are what a printer obeys, so when a number must be exact, sum the moves. When a ballpark is enough, the footer is fine.

The grams line is the exception: 0.00 g because this filament preset stores a density of 0, and weight is volume × density. Length and volume check out; weight is void until the preset carries a real density (PLA is about 1.24 g/cm³, which would make this cube ≈ 4.0 g).

Claim 4: what the plastic is doing

The slicer labels every path. Counting the ;TYPE: markers for the cube:

100  Outer wall        94  Sparse infill
100  Inner wall        94  Internal solid infill
 98  Top surface        1  Skirt
  1  Custom

A story in counts: every layer has outer and inner walls (100 each — two wall loops per layer, as the process preset's wall_loops: 2 promised); 94 layers have sparse infill at the preset's 20% density; the top closes over near the end; and there is exactly one skirt, the warmup loop around the part. When a real print looks wrong — missing infill, a wall short — this table is where the file either confesses or clears itself.

The habit

Slice. Then, before the file leaves the computer: header, layer counts, filament sum, type table. Five minutes with a script turns "the slicer said so" into "the file shows so" — and the day a preset is wrong for your printer, the file will show that too.