Other custom G-Code

You can also embed custom g-code at before and after every layer change, on tool (nozzle) changes and between sequentially-printed objects.

Here’s an example of using before layer change G-code for changing temperatures on a temperature tower. This model consists of 10mm segments which are printed starting at 235C and decreasing by 5C at each 10mm layer. Note that layer_z is the PrusaSlicer placeholder for the current nozzle height in mm, not layers.

When inserted int PrusaSlicer under Printer Settings->Custom G-code->Before layer change G-code, this code compares the current height to the height at which each segment begins (multiples of 10mm at the start of each layer. The first range matched will terminate the tests, so we start testing for the lowest tiers first (10mm) and working our way up to the highest (110mm), settings extruder temps along the way (M104 Sxxx).

Listing 14 PrusaSlicer layer change g-code
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
;BEFORE_LAYER_CHANGE
; layer_z is height of current layer in mm
G92 E0.0
;[layer_z]
{if layer_z <= 10}M104 S235
{elsif layer_z <= 20}M104 S230
{elsif layer_z <= 30}M104 S225
{elsif layer_z <= 40}M104 S220
{elsif layer_z <= 50}M104 S215
{elsif layer_z <= 60}M104 S210
{elsif layer_z <= 70}M104 S205
{elsif layer_z <= 80}M104 S200
{elsif layer_z <= 90}M104 S195
{elsif layer_z <= 100}M104 S190
{elsif layer_z <= 110}M104 S185
{endif}

Contact and feedback

You can find me on the Prusa support forums or Reddit where I lurk in many of the 3D printing-related subreddits. I occasionally drop into the Official Prusa 3D discord server where I can be reached as bobstro (bobstro#9830).

Last updated 20210110