AI and 3D printing · Part 4 of 4

From model to printer file: STL, 3MF, slicing and G-code

The printer never sees your model. It sees G-code: thousands of moves and temperatures written by the slicer. Here is how to get from one to the other.

You have a model. Before it can print, a slicer cuts it into layers and writes G-code: the exact path of the nozzle, its speed, and the temperatures, line by line. The AI can help here too, but less than you'd think: the slicer's defaults and one test print do most of the work.

Step 1: export the right file

FileWhat it holdsUse it for
STLTriangles only. No units: everyone assumes millimetres.Any slicer. The universal format.
3MFMesh plus units, colours, several parts, and slicer settings.Sharing a ready-to-print project. Becoming the standard.
STEPThe exact solid, curves and all.Opening the design in other CAD (FreeCAD, Fusion, Onshape). Some slicers take it directly.
G-codeMachine moves for one printer, one material, one set of settings.Sending to the printer. Not for sharing.

Every script in this series exports STL and STEP. In CadQuery that's two lines:

cq.exporters.export(knob, "knob_m6.stl")
cq.exporters.export(knob, "knob_m6.step")

For curved parts, the STL export has a tolerance setting that controls how many triangles approximate each curve. The default is fine for most parts; ask for a finer one if you can see facets on round surfaces.

Step 2: slice it

In the slicer window (the normal way)

  1. Open OrcaSlicer (or PrusaSlicer, Cura, Bambu Studio: they're all similar). Pick your printer and filament on first run.
  2. Drag in the STL. Check it sits flat; use “lay on face” if not.
  3. Press Slice. Read the estimated time and grams.
  4. Scrub through the layer preview. Look for overhangs shown in a warning colour, and anything floating in mid-air.
  5. Export or send the G-code to the printer.

The settings that matter

SettingStart withWhy
Layer height0.2 mmThinner is smoother and slower.
Walls3More walls add more strength than more infill.
Infill15–20% gyroidThe inside pattern. 100% is rarely needed.
SupportsOffDesign them out (all four parts here need none).
BrimOff; 5 mm for tall thin partsStops corners lifting.
Spiral vase modeOnly for the vaseOne continuous wall, no top, no seam. Prints in about an hour.

From the command line (what the AI does)

OrcaSlicer can also slice without opening a window, which lets an AI assistant slice a part, read the results and tell you the print time. This is the command I used for the knob, with three small settings files for a generic 220 mm printer, 0.4 mm nozzle and PLA (they're in the download):

orca-slicer --load-settings "printer.json;process.json" \
            --load-filaments "pla.json" \
            --arrange 1 --slice 0 --export-statistics \
            --export-3mf knob_m6.3mf --outputdir out \
            knob_m6.stl

It writes plate_1.gcode, a 3MF project and a statistics file. The results for three of the parts:

PartLayersPLAEstimated time
M6 knob9010.0 g1 h 05 m
24-tooth gear409.6 g1 h 01 m
Pi 5 case base12026.3 g1 h 13 m

Times are the slicer's estimate for a generic printer at modest speeds; a modern fast printer will be quicker. At around £20 a kilo, the knob costs about 20p in plastic.

Step 3: look at the G-code before you print

G-code is plain text. The start of the knob file:

; total layers count = 90
; estimated printing time (normal mode) = 1h 4m 32s
G28 ; home
M190 S60
M109 S215
...
;TYPE:Outer wall
G1 F1800
G1 X129.573 Y112.779 E.0131
G1 X129.237 Y112.754 E.01142

G28 homes the axes. M190 S60 waits for the bed to reach 60 °C and M109 S215 waits for the nozzle to reach 215 °C. G1 is “move in a straight line”: X and Y are the position in millimetres, F the speed, and E how much filament to push. Anyone who has run a CNC machine will recognise it: it's the same language family. The knob is 140,500 of these moves.

Reading those first lines is worth the 30 seconds. My first slice said M190 S35: the filament settings gave 60 °C for one type of build plate, but the printer profile defaulted to another. PLA on a 35 °C bed tends to let go halfway through a print. Asking the AI “what bed and nozzle temperature does this G-code use?” would have caught it just as quickly.

Because it's text, an AI can read it back and draw any layer. This is layer 16 of the knob, coloured by what the nozzle is doing:

Toolpath of one layer of the knob: three orange outer and inner wall loops following the fluted edge, a hexagonal set of wall loops around the nut trap in the middle, and blue wavy gyroid infill between them.
Three wall loops round the flutes and round the hex nut trap, gyroid infill between. Drawn from the G-code by a 35-line script in the download.

This picture answers questions makers actually ask. Is the wall round the nut thick enough? (Three passes, about 1.3 mm.) Does the infill reach the flutes? (Yes.) You can ask the AI the same questions in words, and it will answer from the file.

Step 4: print, test, adjust

All the example files

Scripts with their prompts, ready-to-slice STLs, the sliced knob as a 3MF, and the minimal OrcaSlicer profiles. 2.4 MB zip.

Download

Check every size against your own parts before printing. The Pi 5 port positions are approximate. None of these parts is designed for load-bearing or safety-critical use.

Need a hand?

Graith Internet builds AI-assisted tools and workflows for small businesses, alongside our Drupal and PHP work. If you want help putting something like this to work in your own business, get in touch.

© 2026 Graith Internet.

Graith Internet is a UK web development company specialising in PHP, Drupal, and AI-assisted development.