Skip to content

Slicer G code Scripts

Miguel Risco-Castillo edited this page Jan 13, 2024 · 22 revisions

This is only a general suggestion; the exact parameters depend on your hardware setup and preferences. These scripts assume a standard Ender 3 V2/S1 with a bed of 220x220 mm or similar.

Note: to enable the leveling system, a valid mesh must be loaded into memory. Verify if you have a valid mesh in memory by opening the mesh viewer.

Cura G-code scripts

Start script:

M201 X500.00 Y500.00 Z100.00 E5000.00 ;Setup machine max acceleration
M203 X500.00 Y500.00 Z20.00 E50.00 ;Setup machine max feedrate
M204 P500.00 R1000.00 T500.00 ;Setup Print/Retract/Travel acceleration
M205 X8.00 Y8.00 Z0.40 E5.00 ;Setup Jerk
M220 S100 ;Reset Feedrate
M221 S100 ;Reset Flowrate

G92 E0 ; Reset Extruder
G28 ; Home all axes
M420 S1 Z2; Use a mesh leveling up to 2mm (a valid mesh must be loaded into RAM);
G1 Z2.0 F3000 ; Move Z Axis up little to prevent scratching of Heat Bed
G1 X0.1 Y20 Z0.3 F5000.0 ; Move to start position
G1 X0.1 Y200.0 Z0.3 F1500.0 E15 ; Draw the first line
G1 X0.4 Y200.0 Z0.3 F5000.0 ; Move to side a little
G1 X0.4 Y20 Z0.3 F1500.0 E30 ; Draw the second line
G92 E0 ; Reset Extruder
G1 Z2.0 F3000 ; Move Z Axis up little to prevent scratching of Heat Bed
G1 X5 Y20 Z0.3 F5000.0 ; Move over to prevent blob squish

End script

G91 ;Relative positioning
G1 E-2 F2700 ;Retract a bit
G1 E-2 Z0.2 F2400 ;Retract and raise Z
G1 X5 Y5 F3000 ;Wipe out
G1 Z10 ;Raise Z more
G90 ;Absolute positioning

G1 X0 Y200 ;Present print
M106 S0 ;Turn-off fan
M104 S0 ;Turn-off hotend
M140 S0 ;Turn-off bed
M84 ;Disable steppers

Prusa/Super Slicer G-code scripts

Start script:

;
; First layer print x min = [first_layer_print_min_0]
; First layer print y min = [first_layer_print_min_1]
; First layer print x max = [first_layer_print_max_0]
; First layer print y max = [first_layer_print_max_1]
; Total layer count = [total_layer_count]
;
M201 X500.00 Y500.00 Z100.00 E5000.00 ;Setup machine max acceleration
M203 X500.00 Y500.00 Z20.00 E50.00 ;Setup machine max feedrate
M204 P500.00 R1000.00 T500.00 ;Setup Print/Retract/Travel acceleration
M205 X8.00 Y8.00 Z0.40 E5.00 ;Setup Jerk
M220 S100 ;Reset Feedrate
M221 S100 ;Reset Flowrate

G90 ; use absolute coordinates
M83 ; extruder relative mode
M104 S[first_layer_temperature] ; set extruder temp
M140 S[first_layer_bed_temperature] ; set bed temp
M190 S[first_layer_bed_temperature] ; wait for bed temp
M109 S[first_layer_temperature] ; wait for extruder temp
G28 ; home all
M420 S1 Z2; Use a mesh leveling up to 2mm (a valid mesh must be loaded into RAM);
G1 Z2 F240
G1 X2 Y10 F3000
G1 Z0.28 F240
G92 E0
G1 Y190 E15 F1500 ; intro line
G1 X2.3 F5000
G92 E0
G1 Y10 E15 F1200 ; intro line
G92 E0

End script

{if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+2, max_print_height)} F600{endif} ; Move print head up
G1 X5 Y170 F{travel_speed*60} ; present print
{if max_layer_z < max_print_height-10}G1 Z{z_offset+min(max_layer_z+70, max_print_height-10)} F600{endif} ; Move print head further up

M140 S0 ; turn off heatbed
M104 S0 ; turn off temperature
M107 ; turn off fan
M84 ; disable motors

Optional

For run a mesh leveling on each print replace the lines:

G28 ; home all
M420 S1 Z2; Use a mesh leveling up to 2mm (a valid mesh must be loaded into RAM);

For non UBL version with:

G28 ; home all
G29 ; Run mesh leveling on every print
C108 ; Close the mesh viewer (optional)

UBL

For load the mesh leveling in UBL, use:

G28 ; home all
G29 L0 ; Load mesh from slot 0 (or use any other previously saved slot)
G29 A ; Activate UBL

For run a UBL mesh leveling on each print:

G29 P1 ; Home automatically and run mesh leveling on every print
G29 A ; Activate UBL
C108 ; Close the mesh viewer (optional)

Show layer number

To show layer number in the printer screen use this script in your Orca/Prusa/Super slicer:

;AFTER_LAYER_CHANGE
;[layer_z]
M117 Layer {layer_num + 1} of {total_layer_count}