Ahn S.-H. 等,Anisotropic material properties of fused deposition modeling ABS,Rapid Prototyping Journal 8(4):248–257,2002。
Popescu D. 等,FDM process parameters influence over the mechanical properties of polymer specimens: A review,Polymer Testing 69:157–166,2018。
Lopes L.R.、Silva A.F.、Carneiro O.S.,Multi-material 3D printing: The relevance of materials affinity on the boundary interface performance,Additive Manufacturing 23:45–52,2018。
Read every line your slicer writes for your printer
Your slicer turns a model into tens of thousands of lines of G-code, and your printer carries them out one by one: move, extrude, heat, change filament. This site starts with a single line and takes you all the way to multi-material tool changes and rewriting a whole file.
New here? Go in this order: Lessons → Simulator → Practice.
Lessons
22 lessons, from a single line to rewriting a whole file
Six parts, best taken in order. Each lesson opens with what you'll be able to do and ends with a quick check; examples with a button load straight into the simulator so you can run them line by line. Your progress is stored only in this browser on this device.
What is G-code?
After this lesson you can: place G-code in the printing workflow; break a line into command, parameters and comment; explain why G-code is called "stateful".
The slicer generates G-code; the firmware reads it line by line and drives the motors and heaters. G-code is the only "language" the two share.
G-code dates back to the numerically controlled machine tools of the 1950s and was later standardized as RS-274 / ISO 6983. 3D printers borrowed its syntax, but each firmware implements only part of it and adds plenty of commands of its own. So 3D-printing G-code is really a family of "dialects": the common commands are the same everywhere, while the details vary.
Anatomy of a line
G1 X120 Y100 E0.67F1800; outer wall
Command: the G1 at the start. The letter gives the category: G is mostly motion and coordinates, M covers miscellaneous functions (temperature, fans, motors), and T selects a tool.
Parameters: pairs like X120 and E0.67, each "a letter plus a number". Their order doesn't matter.
Comment: the firmware ignores everything after a semicolon. Slicers write layer numbers, feature types and slicing settings in comments, which makes them very useful when you read a file.
You may also see lines like this in a serial log: N12 G1 X10*98. N12 is a line number and *98 is a checksum (the XOR of all the characters before it). Host software adds them when it sends code over USB serial, and if a checksum doesn't match, the firmware asks for the line again. Files exported by a slicer usually don't have them.
G-code is stateful
The firmware remembers a number of settings, and every later line is interpreted under them: the current position, whether coordinates are absolute or relative, whether extrusion is absolute or relative, the current speed F, the target temperatures and the current tool. For example, G1 X10 means "go to X=10" in absolute mode but "move 10 mm to the right" in relative mode. When you read G-code you have to keep track of this state in your head; the state panel at the bottom right of the simulator does it for you.
Common mistake: copying a block of code from the middle of a file and running it on its own. It depends on modes, temperatures and a position set earlier in the file, so on its own it may do something completely different.
Coordinates and homing
After this lesson you can: name the directions of X, Y and Z; explain why a printer must home after power-on; understand that G92 changes the "recorded position", not the actual position.
On most printers the origin is at the front-left corner of the bed, with X pointing right, Y toward the back and Z up. There are exceptions, so your machine's firmware configuration has the final say.
A stepper motor only knows how many steps it has taken, not where it is. After a power cycle the print head could be anywhere, and the firmware has no idea. G28 moves each axis slowly until it hits an endstop or the probe triggers, and only then does the firmware record that position as the origin.
G28; home all axesG28 X Y ; home only X and YM114; ask the firmware to report the current position
On many machines with a probe, homing Z first moves the probe to the middle of the bed and then probes down, so the probe doesn't end up off the edge of the bed.
Software endstops: once homed, the firmware knows the travel range and refuses moves beyond it. Marlin turns them off or on with M211 S0/S1; Klipper simply reports "Move out of range" when a move goes past the limit.
Moving before homing: Klipper refuses with an error; Marlin depends on its configuration.
G92: change the record, not the position
G92 X0 Y0 means "call the spot where the print head is now (0, 0)". The head doesn't move; every coordinate after this is measured from the new origin.
G1 X50 Y50 F3000; head goes to machine coordinates (50, 50)G92 X0 Y0 ; call this spot (0, 0)G1 X10 ; actually goes to machine coordinates (60, 50)
By far the most common everyday use is G92 E0, which resets the extruder coordinate to zero. Lesson 7 covers it in detail.
Common mistake: changing the XY coordinates with G92 while testing by hand and then forgetting about it, so every absolute coordinate after that is shifted. Running G28 again puts things right.
Linear moves and speed
After this lesson you can: write moves with G0 / G1; convert between F and mm/s; explain why the actual speed often falls short of F.
G0 and G1 are both straight-line moves. By convention G0 is used for travel moves without extrusion and G1 for printing, but in most firmware the two behave exactly the same. Any axis you leave out stays where it is:
G1 X50 Y50 F6000; diagonal move to (50, 50)G1 X80 ; changes only X, Y stays at 50G1F1800; no move, just sets the speed to 1800 for what follows
F is in mm/min
F is the combined speed along the path (on a diagonal move it is measured along the diagonal), and its unit is millimeters per minute, not millimeters per second. It is modal: once set, it stays in effect until the next F appears. PrusaSlicer and Bambu Studio often put F on a line of its own, which relies on exactly this.
Change either one and the other converts automatically. Typical ranges, depending on the machine: first layer 20–30 mm/s (F1200–F1800), outer walls 40–200 mm/s, travel 150–500 mm/s.
The actual speed is often below F
The print head has mass and can't change speed instantly. The firmware speeds up, cruises and then slows down according to the acceleration settings. On a short segment it has to start slowing down before it ever reaches F, so on small parts and detailed areas the actual speed is far below the set value. Lesson 15 covers the commands that control acceleration.
Common mistake: putting a mm/s number straight into F. G1 X100 F60 means 1 mm per second, so slow that it looks like nothing is moving.
Absolute and relative positioning
After this lesson you can: work out where the same line goes under G90 and under G91; know when to use relative positioning and how to clean up after it.
G90 is absolute positioning: each number is the target position. G91 is relative positioning: each number is an offset from the current position. Here is where the same code ends up after each line in the two modes:
The print paths a slicer generates almost always use absolute coordinates, because every point's position is worked out in advance. Relative positioning suits "move this far in some direction, wherever you are now" jobs:
G91; switch to relativeG1 Z10 F600; raise another 10 mm, however tall the print isG90; always switch back to absolute
Lifting Z in the end G-code, small moves inside macros and manual jogging are all typical uses of relative positioning.
In Marlin, G90/G91 switch the E axis along with the others; in Klipper, G91 also makes E relative. That's why a slicer's start G-code always sends G90 first and then sets E separately with M82/M83. Lesson 7 comes back to this trap.
Common mistake: using G91 and forgetting to switch back to G90. Every absolute coordinate after that is treated as an offset, and the print head charges off past the end of its travel.
Arcs: G2 / G3
After this lesson you can: read the direction and the center notation of G2/G3; know what a slicer's "arc fitting" does and when you can't use it.
I and J are the center's offset from the start point, and they stay relative even in G90 absolute mode. Direction is judged in top view (looking down).
G2 X95 Y110 I15 J0 E3.3; starts at (95,110) and ends there again: full clockwise circleG3 X95 Y80 I-15 J0 E1.65; counterclockwise half circleG2 X125 Y60 R20 E1.18; R form: radius 20 given directly, takes the shorter arc
The I/J form can draw any arc, including a full circle (end point equal to the start point).
The R form gives only the radius: a positive R takes the arc under 180°, a negative R the arc over 180°. The R form can't draw a full circle.
The firmware splits an arc into many short straight segments before executing it, so arcs only make the file shorter; they don't make the motion any "rounder".
Firmware support
Marlin needs ARC_SUPPORT enabled (on by default in many configurations) and supports both I/J and R; Klipper needs [gcode_arcs] in its config and supports only I/J; RepRapFirmware supports arcs natively.
PrusaSlicer, OrcaSlicer and others have an "Arc fitting" option that merges runs of short straight segments into G2/G3. The file gets much smaller, and streaming it over USB serial (with OctoPrint, for example) is less likely to stutter. The catch is that your firmware has to support arcs.
Common mistake: turning on arc fitting when arc support isn't enabled in the firmware. The firmware ignores the arcs or throws an error, and the round parts are simply missing.
E axis and extrusion amount
After this lesson you can: work out how much E a line needs; understand how line width and layer height affect extrusion; estimate whether the volumetric flow will exceed what your hotend can handle.
E is the extruder axis, and its unit is length of filament (mm). The volume of filament the extruder feeds in is the volume of plastic that comes out of the nozzle:
E × filament cross-section = line length × line cross-section
An extruded line has rounded sides, not square ones. The rounded model is closer to the real cross-section and gives a slightly smaller E.
Volumetric flow: the hotend's limit
Volumetric flow = speed × line cross-section, in mm³/s. A hotend can only melt so much plastic per second: a typical standard hotend manages about 10–15 mm³/s with PLA, and a high-flow hotend can reach 20–30 or more, depending on the model and material. Go past the limit and the plastic doesn't have time to melt, so you get under-extrusion, a pale surface, and an extruder that skips with a clicking sound. If you want to print faster, check the flow first.
The slicer's "flow ratio / extrusion multiplier" (usually 0.9–1.0) scales every E value; during a print you can also use M221 S95 to set it to 95% temporarily.
Common mistake: Setting the wrong filament diameter. If you load 2.85 mm filament but the slicer is set to 1.75, the cross-section areas differ by (2.85/1.75)² ≈ 2.65×, and you get severe over-extrusion.
M82 / M83 and G92 E0
After this lesson you can: read both absolute and relative extrusion; know why you should run G92 E0 regularly; avoid the trap where G90 changes the E mode.
M82 is absolute extrusion: E is a running total ("extrude until the total reaches this"). M83 is relative extrusion: E is "how much to extrude on this move". The same numbers mean completely different things in the two modes:
In absolute mode, each move extrudes 0.4 mm, and the last line, E0.4, takes E from 1.2 back to 0.4: a 0.8 mm retraction. In relative mode, the three moves extrude 0.4, 0.8 and 1.2 mm, more each time, and the last line extrudes another 0.4.
Why G92 E0
Whichever mode you use, the firmware keeps a running E coordinate internally. After a few hours of printing it can pass 10,000, floating-point precision drops, and small extrusion amounts are no longer computed accurately. That's why many profiles add a G92 E0 at every layer change to reset it. In relative mode, PrusaSlicer warns you to add this line if it's missing.
Which is better
Most modern slicer profiles use M83. In relative mode you can see each line's extrusion at a glance, and inserting or deleting code in the middle of the file doesn't affect the lines after it; in absolute mode, changing any segment means recalculating every E value after it.
Common mistake: On Marlin, writing M83 first and then G90. G90 switches E back to absolute mode too, so each small value that follows is read as "total up to 0.4 mm": almost nothing extrudes, or you get a big retraction. The correct order is G90 first, then M83. When you change modes inside a Klipper macro, you can use SAVE_GCODE_STATE / RESTORE_GCODE_STATE to save and restore them.
Retraction, Z hop and wipe
After this lesson you can: read the full sequence of moves around a travel; know roughly how to choose a retraction length; use firmware retraction.
The plastic in the nozzle is under pressure, so it keeps oozing out during travel moves and pulls thin strings between parts. Retraction pulls the filament back a little before a travel to release that pressure. A typical travel looks like this:
G1E-0.8F2100; 1. Retract 0.8 mm (relative extrusion)G1 Z0.6 F600; 2. Z hop to avoid hitting printed parts (optional)G1 X80 Y40 F9000; 3. TravelG1 Z0.4 F600; 4. Drop back to the current layerG1E0.8F2100; 5. Unretract to restore pressure
Retraction length: direct drive (extruder on the print head) is typically 0.5–1.5 mm; Bowden (filament runs through a long tube) is typically 3–6 mm, because the tube flexes and has play.
Retraction speed: typically 25–45 mm/s (F1500–F2700). Too fast and the extruder can slip and grind the filament; too slow and it doesn't work well.
Wipe: while retracting, the nozzle moves a short way back along the line it just printed, smearing leftover plastic onto the part.
Fewer travels: PrusaSlicer's "Avoid crossing perimeters" and Cura's Combing keep travel moves inside the part where possible, so you need fewer retractions and still get no strings.
Firmware retraction: G10 / G11
The slicer can write just G10 (retract) and G11 (unretract) and leave the length and speed to the firmware. The benefit is that you can tune them without re-slicing. Marlin uses M207 to set retraction and M208 to set unretraction; Klipper needs [firmware_retraction] and is tuned with SET_RETRACTION RETRACT_LENGTH=0.8.
Common mistake: Fighting stringing by just increasing retraction. Retracting too far pulls softened plastic up into the heat break, where it cools and jams (especially common with PLA). Stringing is more often caused by a temperature that's too high or by damp filament.
Pressure advance (linear advance)
After this lesson you can: explain why corners bulge and line starts come out thin; set up pressure advance in all three firmwares.
Molten plastic is slightly compressible, and the filament and tube are a bit springy, so there's a lag between the extruder pushing and plastic leaving the nozzle. When the print head accelerates, the flow can't keep up and the start of the line comes out thin; when it decelerates, the pressure hasn't been released yet, so corners bulge and collect blobs.
Pressure advance compensates by having the extruder push a little more or a little less ahead of time, based on the current extrusion speed: extra push ≈ K × extrusion speed. The larger K is, the stronger the compensation.
Typical K values: around 0.02–0.1 for direct drive, and possibly 0.3–1 for Bowden. Different materials and temperatures need different values.
Calibration: print a dedicated test pattern or test tower and pick the setting with the cleanest corners. OrcaSlicer has a built-in pressure advance calibration; in Klipper you can do it with TUNING_TOWER.
The old Linear Advance 1.0 in earlier Marlin versions used different units, with K values often in the tens. Before you use a value you found online, check which version it's for.
Because it depends on the material, it usually goes in each filament's "filament start G-code" rather than in the printer's start G-code.
Common mistake: Setting K too high. Corners under-extrude, gaps appear where lines start and end, and with Bowden the extruder may even jitter back and forth.
Temperature control
After this lesson you can: tell "set" and "wait" temperature commands apart; write a heating sequence that saves time; know which temperature safety settings to leave alone.
Heater
Set and continue
Set and wait for temp
Nozzle
M104 S210
M109 S210
Bed
M140 S60
M190 S60
The T parameter selects the hotend: M104 T1 S170 sets only the second one. Without T, it applies to the current tool.
On Marlin, M109 S waits only when heating up; M109 R waits whether heating or cooling. The bed's M190 works the same way.
S0 turns the heater off.
Start both heaters first with M140 and M104, then wait with M190 and M109, so they heat up in parallel.
M140 S60 ; Start heating the bedM104 S150 ; Nozzle to 150°C first: soft but won't ooze, good for levelingG28M190 S60 ; Wait for the bedM109 S210 ; Heat nozzle to print temp and wait
Typical temperatures for common materials
Material
Nozzle
Bed
PLA
190–220°C
50–60°C
PETG
230–250°C
70–85°C
ABS / ASA
240–260°C
90–110°C
TPU
210–240°C
30–60°C
Follow the filament manufacturer's recommendations. For a full comparison of 20 common filaments, see the Filaments page.
Temperature safety
Firmware has "thermal runaway protection": if a heater is on but the temperature doesn't rise for a long time, or suddenly drops (for example, because the thermistor has come loose), it shuts the printer down immediately. This is the last line of defense against fire, so never disable it. If the temperature swings a lot, run PID autotune: M303 E0 S210 C8 on Marlin, PID_CALIBRATE HEATER=extruder TARGET=210 on Klipper. Also, by default Marlin won't extrude while the nozzle is below 170°C (cold extrusion protection).
Common mistake: The start G-code has M104 but no M109, so printing starts before the nozzle is hot: the first layer doesn't extrude, or cold extrusion protection blocks it.
Fans and cooling
After this lesson you can: control the part cooling fan with M106; know how to run the fan for different materials and layers.
M106 S255 ; Part fan at full speed (range 0–255)M106 S128 ; About 50%M106 P1 S255 ; P selects which fanM107; Turn off the part fan
The part cooling fan blows on freshly extruded plastic so it sets quickly. The hotend cooling fan is a separate fan: the firmware usually turns it on automatically once the hotend passes a set temperature, and M106 doesn't control it.
Some machines use the P parameter to address several fans. On Bambu printers, for example, P1, P2 and P3 are the part cooling fan, the auxiliary fan and the chamber fan.
The fan is usually off for the first layer so the plastic sticks better to the bed, then ramps up over the next few layers. The slicer writes these M106 commands for you.
Bridges and overhangs need more cooling, so the slicer temporarily raises the fan speed before those features.
"Minimum layer time": when a layer is small, the slicer slows down so each layer gets enough time to cool.
Material
Part cooling fan
PLA
High; basically full speed after the first layer
PETG
Medium; too much weakens layer adhesion
ABS / ASA
Very low or off; cooling too fast causes warping and cracks
TPU
Medium
Common mistake: Running the fan at full speed for ABS. The layers shrink unevenly, and the part warps or even splits between layers.
Start and end G-code
After this lesson you can: read a complete start G-code and end G-code; know where bed leveling and Z offset go.
The slicer puts the "start G-code" at the beginning of the file and the "end G-code" at the end. Their job: whatever state the printer was in before, bring it to a known starting point, and once the print is done, finish up safely.
G90; Absolute positioningM83; Relative extrusion (after G90)M140 S60 ; Start heating the bedM104 S150 ; Preheat nozzle to a temp where it won't oozeG28; HomeM190 S60 ; Wait for bed (leveling is more accurate once it has expanded)G29; Auto bed leveling (Klipper: BED_MESH_CALIBRATE)M109 S210 ; Nozzle to print temperatureG1 Z0.3 F720G1 X5 Y20 F6000G1 Y200 E15F1500; Prime line: flush old plastic from the nozzle, build pressureG1 X5.4 Y20 E15F1500; And a second line backG1E-0.8F2100; Retract, ready to start
Leveling: a probe measures several points on the bed to build a height mesh, and Z follows the mesh with small corrections during the print. Machines without a probe rely on manual leveling screws.
Z offset: the height difference between the probe's trigger point and the nozzle tip. On Marlin you set it with M851 Z-1.20 (save with M500) and fine-tune it during a print with M290 (babystepping); on Klipper you fine-tune it with SET_GCODE_OFFSET Z_ADJUST=-0.02. If the first layer is too high or too low, check this first.
Real profiles don't hard-code temperatures; they use slicer variables instead. See the Slicers page.
; End G-codeG1E-2F2100; Retract so it doesn't ooze after stoppingG91G1 Z10 F600; Relative lift: safe however tall the print isG90G1 X0 Y200 F6000; Bring the bed forward for easy part removalM104 S0 ; Nozzle offM140 S0 ; Bed offM107; Fan offM84; Motors off
Common mistake: Writing G1 Z10 in absolute coordinates in the end G-code. If the part is taller than 10 mm, the nozzle drives down into it. Use a relative lift, or use slicer variables to compute "current top layer + 10".
Anatomy of a sliced file
After this lesson you can: open any sliced file, know where each part is, and jump straight to the part you want.
A print that takes a few hours usually runs to hundreds of thousands or even millions of lines, and almost all of them are layer-by-layer moves.
Header: estimated time, filament length and weight. PrusaSlicer and OrcaSlicer also embed a preview thumbnail as base64 text in comments (; thumbnail begin), which is what the printer's screen shows as the preview.
Layers: each layer starts with a layer marker comment. To jump to a layer, search for ;LAYER_CHANGE (PrusaSlicer), ; CHANGE_LAYER (Bambu Studio) or ;LAYER: (Cura).
Slicer settings: PrusaSlicer writes every setting as comments at the end of the file; Cura writes them as lines starting with ;SETTING_3. When you get someone else's file, look here to see which settings they used.
Open one of your own sliced files in a text editor and follow along, or load it in the simulator with "Open my file" and step through it layer by layer.
Layers and features
After this lesson you can: read the complete code of a layer change, recognize each slicer's feature comments, and understand where seams come from.
A typical layer change (PrusaSlicer style, relative extrusion):
;LAYER_CHANGE;Z:0.4;HEIGHT:0.2G1E-.8F2100; retractG1 Z.4 F720; move up to the new layer (PrusaSlicer drops the leading 0)G1 X100 Y100 F9000; travel to this layer's start point, which is the seamG1E.8F2100; unretract;TYPE:External perimeterG1 X120 Y100 E.749F1800
Seams
Every loop of outer wall has a start and an end, and that spot leaves a small mark. The slicer can line these marks up into one vertical line (Aligned), put them at the back (Rear), scatter them randomly (Random) or place them wherever is closest (Nearest). In the G-code, the seam is where each layer's outer wall starts: the start point of its first G1.
Feature comments by slicer
Feature
PrusaSlicer ;TYPE:
Bambu Studio ; FEATURE:
Cura ;TYPE:
Outer wall
External perimeter
Outer wall
WALL-OUTER
Inner wall
Perimeter
Inner wall
WALL-INNER
Sparse infill
Internal infill
Sparse infill
FILL
Top surface
Top solid infill
Top surface
SKIN
Support
Support material
Support
SUPPORT
The wipe tower is called Wipe tower in PrusaSlicer and Prime tower in Bambu Studio and OrcaSlicer. The simulator's "By feature" coloring and its File analysis tab sort moves by reading exactly these comments.
Common mistake: automating with feature comments (for example in a post-processing script) but matching only one slicer's names. Switch slicers, or even slicer versions, and the script stops working.
Speed, acceleration and motion settings
After this lesson you can: explain why short segments never reach the set speed, spot the acceleration commands in a file, and know which multipliers you can adjust during a print.
The firmware plans speed within its acceleration limits. A long segment speeds up to F and cruises there; a short one has to start slowing down halfway, before it ever gets to F.
Command
Purpose
Notes
M201
Max acceleration per axis
mm/s², e.g. M201 X3000 Y3000
M203
Max speed per axis
In Marlin the unit is mm/s, not mm/min
M204
Current acceleration
Marlin: P for printing, R for retracts, T for travel
M205
Jerk / cornering speed
X/Y set jerk, J sets junction deviation (one or the other, depending on how the firmware is configured)
M220
Speed multiplier
M220 S80: every speed times 80%
M221
Flow multiplier
M221 S95: extrusion times 95%
Modern slicers write a different M204 for each feature: low acceleration on outer walls for a clean surface, high acceleration on infill to save time.
The Klipper equivalent is SET_VELOCITY_LIMIT VELOCITY=300 ACCEL=5000 SQUARE_CORNER_VELOCITY=5, and Klipper also accepts M204 S.
Input shaping suppresses ringing at high acceleration. Klipper uses [input_shaper], tuned with an accelerometer that measures the resonant frequencies; recent Marlin versions use M593.
Common mistake: raising only the speeds in the slicer and finding that print time barely changes. Small parts are limited by acceleration and never get up to speed, so check acceleration and volumetric flow first.
T commands and three kinds of hardware
After this lesson you can: describe how the three kinds of multi-material printers are built differently, and what T1 actually does on each one.
The same T1 command triggers completely different actions on each of the three.
Type
What T1 does
Pros
Main problems
Multi-nozzle / toolchanger
Another nozzle takes over; the firmware compensates for the offset between nozzles
Fast tool changes, almost no waste
Idle nozzles ooze; offsets need calibrating; expensive
Single nozzle, many feeds
Unloads the current filament, loads the new one, then purges
4–16 colors, relatively cheap
Every change needs a purge: lots of waste and time
Mixing hotend
Switches to a "virtual tool" with a preset mix ratio
Can print color gradients
Uneven mixing; color transitions still need purging
IDEX (independent dual X) machines can also print in duplication and mirror modes, which Marlin switches with M605.
Splicers (such as the Mosaic Palette) fuse filaments of different colors into a single strand outside the printer. The printer only ever sees one filament, so the file has no T commands.
A tool change, step by step
After this lesson you can: list the steps of a tool change on single-nozzle and multi-nozzle machines, and what you will see when each step goes wrong.
Single nozzle, many feeds (MMU, AMS and similar)
Shape the tip: before unloading, the filament tip has to be clean, or it won't come out or will jam in the selector. PrusaSlicer uses ramming plus back-and-forth cooling moves to squeeze the tip thin and shape it; Bambu machines simply cut the filament with a blade.
Unload: pull the old filament back to the selector or buffer.
Load: feed the new filament until it reaches the nozzle.
Purge: old material is still in the melt zone, so enough new material has to be pushed through to flush the old color out. It goes into a wipe tower, into the model's infill, or straight out the back of the machine (Bambu's purge chute).
Return to the model: retract, move, unretract and carry on printing.
Multi-nozzle / toolchanger
Retract and lift the current nozzle.
Drop to standby: M104 T0 S170 cools the idle nozzle to a temperature where it won't ooze. Some slicers start preheating the next nozzle a few seconds before the change to cut the wait.
Switch tools: T1. The firmware applies the new nozzle's XY offset (M218 in Marlin, SET_GCODE_OFFSET in a Klipper macro).
Heat and wipe: M109 T1 S215, then clean off any oozed plastic on the wipe tower or a brush.
The Multi-material page takes a dual-extruder tool change apart line by line, so you can read the two side by side.
Common mistake: setting a small purge volume on a single-nozzle machine to save filament, so the first few layers of the new color come out streaked with the old one. It is worst when you switch from a dark color to a light one.
Reducing purge waste
After this lesson you can: read a purge volume matrix, estimate how much filament a multicolor print will waste, and list several ways to waste less.
On a single-nozzle machine, how much has to be purged at each change depends on which color you change from and which you change to. The slicer keeps a matrix with the purge volume (in mm³) for every pair of colors:
From ↓ To →
White
Red
Black
White
–
Fairly low
Low
Red
Fairly high
–
Low
Black
Highest
High
–
Illustrative only. A dark color stands out in a light one, so dark-to-light changes need the biggest purge. The slicer calculates the actual values from the colors, and OrcaSlicer and Bambu Studio also have an overall flushing multiplier.
Estimate the waste
Ways to waste less
Purge into the model: send the purge into infill or support that nobody will see (PrusaSlicer: "Wipe into this object's infill" / "Wipe into this object"; Orca / Bambu: "Flush into objects' infill" / "Flush into objects' support").
Fewer changes per layer: the slicer orders the colors so the last color on each layer is the first color on the next (the two-color example in the simulator works this way).
Design for it: color only the outer surfaces and use a single material inside; where you can, split colors by height instead of putting every color on every layer.
Choose the color order: within what the matrix allows, plan more light-to-dark changes and fewer dark-to-light ones.
Change the hardware: multi-nozzle machines need almost no purging, at the cost of ooze and offset problems.
Once you have a real sliced file, the simulator's File analysis tab shows what share of the total filament goes to the wipe tower and purging.
Manual color changes and mixing
After this lesson you can: change colors at chosen layers on a single-color printer, and read the mix-ratio commands of a mixing hotend.
M600: pause for a filament change
You can change colors by layer without any multi-material hardware. M600 retracts, lifts, parks the print head off to the side and unloads the filament, then waits for you to load the new filament and confirm. After that it feeds in, purges, returns to where it left off and keeps printing.
PrusaSlicer: in the preview, click "+" on the layer slider on the right to add a color change.
OrcaSlicer / Bambu Studio: right-click the layer slider and choose to add a color change or a pause.
Cura: Extensions → Post Processing → Modify G-Code, then add the "Filament Change" or "Pause at height" script.
Marlin supports M600 natively (with ADVANCED_PAUSE_FEATURE enabled); in Klipper you have to define an M600 macro yourself, usually one that calls PAUSE.
Mixing hotend
M163 S0 P0.7 ; channel 0 gets 70%M163 S1 P0.3 ; channel 1 gets 30%M164 S2 ; save this mix as virtual tool T2T2; from now on, push both filaments at 7:3
Marlin also has M166, which changes the mix with height to blend from one virtual tool into another. All of these commands need MIXING_EXTRUDER enabled in the firmware.
Common mistake: using the slicer's color change on a Klipper machine and finding that the print never pauses. The M600 macro hasn't been defined, so Klipper reports "Unknown command" and skips it.
Talking to your printer: debug commands and safety
After this lesson you can: query the printer's status and save settings from a console, and know which commands are risky.
The OctoPrint terminal, Pronterface, and the Mainsail / Fluidd console all let you send G-code straight to the printer. The firmware replies ok after each line it finishes. During long-running commands (such as waiting for temperature) it replies busy or reports temperatures periodically.
Command
What it does
In Klipper
M105
Report temperatures
Also supported
M114
Report current position
GET_POSITION gives more detail
M119
Report endstop states
QUERY_ENDSTOPS
M503
List current settings
Settings live in printer.cfg
M500
Save settings to EEPROM
SAVE_CONFIG
M502
Restore factory defaults (then M500)
No equivalent
M112
Emergency stop
Also supported; then FIRMWARE_RESTART
Risky commands
M211 S0 turns off software endstops: you can then move past the travel limits, and any crash is on you.
M302 P1 allows cold extrusion: use it only to debug the extruder. Forcing cold filament through grinds the filament or damages the gears.
Never make any change that disables thermal runaway protection.
When you test newly written code, first do a "dry run" with the nozzle raised and the heaters off. Once the motion looks right, heat up and print for real. Always be ready to cut the power.
After this lesson you can: tell what may go wrong when the same G-code runs on different firmware, and know where to look up a command you don't recognize.
Marlin
Klipper
RepRapFirmware
Runs on
The printer's mainboard
A host computer (e.g. Raspberry Pi) does the math; the mainboard only executes
The mainboard (e.g. Duet)
Configuration
Edit Configuration.h before compiling; some settings can be saved to EEPROM with M500
Text file printer.cfg; restart to apply changes
config.g and other files on the SD card
Macros
Limited, M810–M819
Jinja2 templates, very flexible
Macros are separate files, with conditionals and loops
Tool change
Native T commands, set up with M217/M218
You write T0/T1 macros yourself
Calls the tfree / tpre / tpost macro files automatically
G10
Firmware retraction
Firmware retraction (needs config)
With P: sets tool offsets and temperatures; without P: retract
M600
Native
Write your own macro
Calls filament-change.g
Arcs
Must be enabled; supports I/J and R
Needs [gcode_arcs]; I/J only
Native
For example, in RepRapFirmware G10 P0 S210 R170 means "tool 0: print temperature 210°C, standby temperature 170°C". It has nothing to do with firmware retraction in Marlin.
When you meet a command you don't recognize, check your firmware's official docs first: Marlin at marlinfw.org/meta/gcode, Klipper at klipper3d.org/G-Codes.html, RepRapFirmware at docs.duet3d.com. This site's Reference also shows which firmware supports each command.
Editing G-code by hand: a temperature tower
After this lesson you can: insert commands at a chosen height, build a temperature tower, and avoid edits that break the printer's state.
A temperature tower is a small tower printed in sections, each at a different temperature. When it's done, you compare which section has the least stringing and the best surface. All it takes is one M104 line inserted at the layer change where each section starts:
;LAYER_CHANGE;Z:2.2M104 S215 ; ← inserted: 215°C from this layer onG1 Z2.2 F720
Use M104, not M109: there's no need to stop and wait while the nozzle cools. The temperature settles over the next few layers instead of leaving a blob on the tower where the print paused.
Three ways to insert code
The slicer's layer slider: PrusaSlicer and OrcaSlicer let you add custom G-code at a specific layer.
Post-processing scripts: the "Post-processing scripts" setting in PrusaSlicer and OrcaSlicer runs your script (Python, for example) automatically after export. Cura has built-in post-processing plugins.
Manual editing: search for the layer marker in a text editor and insert the line directly. Good for one-off changes.
Checklist before you edit
If the inserted code changes a mode (G91, M82, etc.), restore it before your inserted block ends.
If you insert moves with E into a file that uses M82 absolute extrusion, use G92 E… afterwards to set E back to its value before the insert. Otherwise every later extrusion will be off.
Make sure inserted moves don't cross already printed parts. Lift Z first if needed.
Run the file in the simulator first and confirm that position, temperature and extrusion are what you expect.
Simulator
Run it line by line and watch the nozzle move
Open your own sliced .gcode or a Bambu / Orca .gcode.3mf, run it line by line, and watch the path in top view or 3D. Click a path to jump to its line of code. "File analysis" shows filament use and time per layer, and "Code check" finds common problems.
Supports .gcode and .gcode.3mf. You can also drag a file onto the code pane on the left. Files are parsed only in your browser and never uploaded.
Loading 3D view…
Scroll or pinch to zoom, drag to pan. Top view shows only the current layer, with the layers below faded.
File analysis
By tool (extruder)
By feature (from slicer comments)
Time per layer
The "ideal print time" counts only path length and F speed, ignoring acceleration, so it is usually shorter than the real time. Weight is estimated from filament diameter and density.
Code check
The check looks only at the file itself. It doesn't know your printer's configuration or what your macros contain. Click a line number to jump to that line.
Multi-material
What the slicer writes for one tool change
Below is typical code for a dual-extruder machine switching from T0 to T1 (what the tool change template looks like once expanded). Single-nozzle multi-material machines follow a similar flow, except that "switch nozzles" becomes "unload, then load", and the purge volume is much larger.
G-code
Why this line
;TYPE:Outer wall (T0 finishes its part of this layer)
The slicer groups moves by tool, keeping it to one tool change per layer where it can.
G1E-0.8F2100
Retract so the old nozzle doesn't ooze or string during the change. Single-nozzle systems retract much more here to shape the filament tip so it unloads cleanly.
G1 Z0.8 F600
Z hop, so the moves after the tool change don't scrape the printed part.
M104 T0 S170
Drop T0, which is about to sit idle, to its standby temperature. A cooler nozzle oozes less, yet heats back up quickly when it is needed again.
M109 T1 S215
Wait for T1 to reach print temperature before continuing. If the slicer preheated T1 earlier, there is almost no wait here.
T1
Switch tools. The firmware applies T1's tool offset; a single-nozzle machine unloads and loads filament here.
G1 X150 Y100 F9000
Move to the wipe tower (also called a prime tower).
G1E0.8F1500
Unretract the amount retracted earlier.
G1 X160 E0.33 …
Print a few lines back and forth on the wipe tower to clear the mixed color and ooze from the nozzle and let extrusion pressure settle.
G1 X115 Y100 F9000
Back to the model, where T1 prints the areas assigned to it.
Purge volume
The main waste with one nozzle
After a tool change on a single nozzle, the old color is still in the melt zone. The slicer sets a purge amount for each "from color, to color" pair in a matrix: light to dark needs little purging, dark to light needs a lot. The purged material can go into the wipe tower, into the model's infill, or straight out of the machine.
Ooze
The main problem with multiple nozzles
An idle nozzle is still hot and slowly leaks filament, leaving specks of the wrong color on the model. Fixes: drop it to standby temperature (M104 T0 S170), retract before the change, use a wipe tower or an ooze shield.
Tool offset
Every nozzle sits in a different spot
The XY distance between the two nozzles has to be calibrated. Marlin sets the hotend offset with M218 T1 X… Y…; Klipper tool change macros usually use SET_GCODE_OFFSET. If the offset is off, the boundary between the two materials will be misaligned.
Template variables
Custom tool change G-code
The slicer's "tool change G-code" can use variables, such as [previous_extruder] and [next_extruder] in PrusaSlicer, or {next_extruder} in OrcaSlicer / Bambu Studio. In Bambu firmware, the AMS tool change logic lives in a proprietary vendor block wrapped in M620 … M621.
Marlin tool change
M217 and M600
M217 sets the swap retraction length, speeds and other tool change parameters. M600 is "pause for filament change": the print pauses until you swap the spool by hand, then resumes. It suits color changes by layer on a single-nozzle machine.
Mixing hotend
M163 / M164
A mixing hotend (several filaments in, one nozzle out) can push several filaments at once in a set ratio. M163 S0 P0.7 and M163 S1 P0.3 set a 7:3 mix, and M164 S2 saves that ratio as virtual tool T2. After that, T2 extrudes with this ratio. Requires MIXING_EXTRUDER enabled in Marlin.
Filaments
20 common filaments: how to print them and how they perform
Print settings and printed-part properties from PLA to PEEK. The values are typical ranges compiled from what several manufacturers' technical data sheets (TDS) usually report, without checking each TDS line by line. Use them to compare and shortlist, not as design allowables. Click a material in the table to see all of its data and matching temperature G-code above it.
Before you read the table: printed strength of the same material can vary by 2× or more with orientation and settings. Z (layer-to-layer) tensile strength is usually only 30–70% of XY, and infill, layer height, line width, nozzle temperature, cooling and dryness all change the result. Nylon values are dry; strength and stiffness drop once they reach moisture equilibrium. The number in brackets after HDT is the test load in MPa. Results at 0.45 MPa are much higher than at 1.8 MPa, so check the load when comparing brands.
Rigidplastics with a modulus of about 0.8 GPa or moreSoftelastomers such as TPU and TPE, below 0.1 GPa
Which materials stick together
Multi-material bonding
How well two materials fuse where they touch in the same print. Poor bonding is not useless: PLA and PETG don't stick to each other, which makes them a good easy-release support interface. Pairs that bond well suit rigid/soft parts and graded structures.
●●●Bonds well; print together directly●●Fair; needs interlocking or tuning●Poor; good as a support interface—No overlapping temperature window, or n/a
PLATeal header: rigid materialTPUPurple header: soft material
The TPU row and column are the soft/rigid pairs. TPU bonds well to PLA and PETG, so you can print soft-touch parts with them directly; with ABS, ASA, PC and PA the bond is fair and the interface needs interlocking.
The ratings are a qualitative summary of manufacturers' multi-material and support compatibility notes (Prusa, Bambu Lab, UltiMaker), overmolding compatibility experience, and Lopes et al. (2018) on material affinity. Brands differ a lot, so test the interface (tensile or lap shear) for critical parts.
PP bonds almost only to PP or SEBS-based TPE. TPU bonds poorly to PP, while SEBS-type TPE bonds well, just as in overmolding.
PVA matches PLA best. BVOH has a wider temperature window and pairs with PETG, ABS and PA. HIPS pairs with ABS / ASA and dissolves in d-limonene.
Fair pairs improve with interlocking geometry at the interface (alternating layers, dovetails or teeth), a hotter nozzle at the interface, and less interface cooling. For what the G-code does during a tool change, see the Multi-material page.
Quick picks
Prototypes, display parts: PLA; PETG if you need some heat resistance and toughness.
Heat-resistant functional parts (<90 °C): ABS / ASA, ASA outdoors. Needs an enclosure and air filtering.
High strength and stiffness: PA-CF / PA-GF, with a hardened nozzle and thorough drying.
High heat, clear or impact-resistant: PC; chamber temperature makes or breaks it.
Chemical contact, lightweight: PP (the hardest to keep from warping), PPS (flame- and chemical-resistant).
Long-term service above 150 °C: PEI, PEKK, PEEK, with a high-temperature printer and annealing.
Flexible, seals, damping: start with TPU 95A; 85A and softer need a direct drive with a short path.
General process tips
Dry hygroscopic materials (PA, PVA, PC, TPU, PETG) as the table says before printing, and feed them from a dry box. Wet filament pops and crackles, strings, prints rough and loses strength.
Carbon- and glass-filled filaments wear brass nozzles quickly. Use hardened steel, ruby or tungsten carbide, 0.4 mm or larger (0.6 mm recommended).
For semi-crystalline materials (PA, PP, PEEK, PEKK, PPS, PET-CF), chamber temperature and annealing strongly affect crystallinity. Annealing raises HDT and stiffness but shrinks the part.
ABS, ASA, HIPS and PC release VOCs and ultrafine particles while printing. Use an enclosure with HEPA and activated-carbon filtering, or vent outside.
A real grade: LUVOCOM 3F PAHT 9825 NT
Compare with the PA row
A high-temperature modified PA6 from LEHVOSS, natural color, with no carbon fiber. These are the conditions from its TDS, so you can see how a specific grade differs from the general ranges above.
Item
Value from the TDS
Drying
Desiccant dryer 110 °C, 6–8 h, or vacuum 100 °C, 4–6 h; dry right before printing
Nozzle
265–290 °C, 0.2 mm or larger
Bed
50 °C or more, with Magigoo PA or Vision Miner Nano Adhesive
Chamber
No heated chamber needed
Speed / layer
30–80 mm/s, layer height 0.1 mm or more
Moisture
Water uptake <0.3% at 23 °C / 24 h (ISO 62); takes about 4× as long as standard PA6 to saturate
Heat
100 °C long term, 120 °C short term (200 h)
Not in the TDS: with no fiber, a regular brass nozzle is fine; an enclosure against drafts and a low or off part fan are advisable. These points are inferred from similar materials. Source: the LUVOCOM 3F 9825 NT TDS hosted on colorfabb.com.
Sources and notes
Manufacturer technical data sheets (TDS): Prusament (PLA, PETG, ASA, PC Blend, PA11-CF); Polymaker (PolyLite, PolyMax, PolyFlex, Fiberon PA6-CF/GF, PC-Max); Bambu Lab Filament Wiki (PLA Basic, PETG HF, ABS, ASA, TPU 95A, PAHT-CF, PA6-GF, PPS-CF, Support for PLA/PETG); UltiMaker material TDS (PVA, Breakaway, Nylon, CPE); BASF Forward AM Ultrafuse range.
High-performance materials: Stratasys ULTEM 9085 / ULTEM 1010 material data sheets; 3DXTech ThermaX PEEK / PEKK / PEI TDS; Victrex PEEK 450G and Arkema Kepstan PEKK resin data.
Ahn S.-H. et al., Anisotropic material properties of fused deposition modeling ABS, Rapid Prototyping Journal 8(4):248–257, 2002.
Popescu D. et al., FDM process parameters influence over the mechanical properties of polymer specimens: A review, Polymer Testing 69:157–166, 2018.
Lopes L.R., Silva A.F., Carneiro O.S., Multi-material 3D printing: The relevance of materials affinity on the boundary interface performance, Additive Manufacturing 23:45–52, 2018.
The ranges summarize the usual levels in the sources above; they were not checked against each TDS line by line and do not list every grade, and the values in the temperature G-code are common picks from within the recommended ranges. For design calculations or published comparisons, use the latest TDS of your exact grade and your own test data. Compiled 2026-10-10.
Slicers
Same job, four ways to write it
Heating, tool changes, and marking layers and features: every slicer has to do these, but the variable names and comment formats differ. Start with the overview table, then switch between the tabs below for full examples. The examples are simplified; your printer's profile has the final say.
No single template; each extruder has its own "Start / End G-code"
T0, T1 are themselves defined as macros
Layer change comment
;LAYER_CHANGE;Z:0.2
; CHANGE_LAYER; Z_HEIGHT: 0.2 (Bambu style; may vary between Orca versions)
;LAYER:0
None; Klipper runs the slicer's file
Feature comment
;TYPE:External perimeter
; FEATURE: Outer wall
;TYPE:WALL-OUTER
None
Default extrusion mode
Depends on profile; official Prusa printers use M83
Depends on profile; most printers use M83
M82 by default; "Relative extrusion" can be turned on
Supports both
This site's simulator recognizes both ;TYPE: and ; FEATURE: feature comments, so files from all three slicers get classified in "By feature" coloring and in File analysis.
Variables go in square brackets [variable] or curly braces {expression}. Inside curly braces you can do math and conditionals. With multiple extruders, temperatures are arrays, indexed with [initial_extruder] or [next_extruder].
; switch from T[previous_extruder] to T[next_extruder]G1E-2F2400; retract{if previous_extruder > -1}M104 T[previous_extruder] S{temperature[previous_extruder] - 40}{endif}M109 T[next_extruder] S{temperature[next_extruder]}T[next_extruder]
When the template writes T[next_extruder] itself, PrusaSlicer stops inserting the T command automatically. You can also just turn on "Ooze prevention" and let standby_temperature_delta cool idle nozzles automatically.
What the output looks like
OrcaSlicer is derived from Bambu Studio (which in turn came from PrusaSlicer). The variable syntax is similar but the names differ: the bed is bed_temperature and the nozzle is nozzle_temperature, for example. On Klipper printers, a common approach is a start G-code that just calls one macro.
M620 S[next_extruder]A ; AMS filament change block startsM204 S9000
G1 Z{max_layer_z + 3.0}F1200; lift above the highest printed pointM400T[next_extruder]; AMS unloads, then loads; ...purge in steps per the purge volume, omitted...M621 S[next_extruder]A ; filament change block ends
The purge amount comes from the "Flushing volumes" matrix: each color pair has its own value, and going from dark to light needs more purging. The full template is long, so use the one that comes with your printer's profile.
What the output looks like (Bambu Studio style)
Cura references any setting with {setting_name}; with multiple extruders you can write {setting_name, extruder_nr}. Conditionals aren't supported. If your start G-code has no heating commands, Cura automatically inserts heat-and-wait commands before it.
; Extruder 2 · end G-code (runs before switching away)G1E-1F2400G91G1 Z2 F600G90; Extruder 2 · start G-code (runs after switching to it)G92 E0
Cura has no global tool change template. What happens at a tool change is spread across each extruder's own start / end G-code. Cooling idle nozzles is handled by the "Standby temperature" in the material settings.
What the output looks like
Klipper doesn't generate G-code; it runs the slicer's file. What sets it apart is that you can write Jinja2 macros in printer.cfg that turn any name into a new command, including T0, T1 and M600.
Start macro
[gcode_macro PRINT_START]
gcode:
{% set BED = params.BED|default(60)|float %}{% set HOTEND = params.HOTEND|default(210)|float %}M140 S{BED}M104 S150 ; preheat without oozingG28M190 S{BED}
BED_MESH_CALIBRATE ; needs [bed_mesh]M109 S{HOTEND}
IDEX machines use [dual_carriage] and SET_DUAL_CARRIAGE. MMU systems (such as ERCF) usually install an extension like Happy Hare, which defines T0, T1 and so on.
Practice
Write it yourself, get it checked
Write code in the box and click "Check": the simulator actually runs it, then checks the result point by point. If you get stuck, step through it in the simulator or look at the reference answer.
Pick an answer and see the explanation right away.