Skip to content

Instantly share code, notes, and snippets.

@leecolarelli
Last active March 10, 2025 03:31
Show Gist options
  • Select an option

  • Save leecolarelli/f5c3402210d722e1e3dba8ae49491892 to your computer and use it in GitHub Desktop.

Select an option

Save leecolarelli/f5c3402210d722e1e3dba8ae49491892 to your computer and use it in GitHub Desktop.
Anycubic Kobra 2 G-code
Start G-code
G28 ;Move X/Y/Z to min endstops
G1 Z0.28 ;Lift nozzle a bit
G92 E0 ;Specify current extruder position as zero
G1 Y3 F1800 ;Move Y to purge point
G1 X60 E25 F500 ;Extrude 25mm of filament in a 5cm line
G92 E0 ;Zero the extruded length again
G1 E-2 F500 ;Retract a little
G1 X70 F4000 ;Quickly wipe away from the filament line
M117
End G-code
M104 S0 ;Extruder off
M140 S0 ;Heatbed off
M107 ;Fan off
G91 ;Relative positioning
G1 E-5 F3000 ;Retract filament
G1 Z+0.3 F3000 ;Lift print head
G28 X0 F3000 ;Home X axis
M84 ;Disable stepper motors
Change filament G-code
@pause ;OctoPrint pause
Pause G-code
@pause ;OctoPrint pause
Start G-code
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 ;Move X/Y/Z to min endstops
G1 Z0.28 ;Lift nozzle a bit
G92 E0 ;Specify current extruder position as zero
G1 Y3 F1800 ;Move Y to purge point
G1 X60 E25 F500 ;Extrude 25mm of filament in a 5cm line
G92 E0 ;Zero the extruded length again
G1 E-2 F500 ;Retract a little
G1 X70 F4000 ;Quickly wipe away from the filament line
M117
End G-code
M104 S0 ;Extruder off
M140 S0 ;Heatbed off
M107 ;Fan off
G91 ;Relative positioning
G1 E-5 F3000 ;Retract filament
G1 Z+0.3 F3000 ;Lift print head
G28 X0 F3000 ;Home X axis
M84 ;Disable stepper motors
Change filament G-code
@pause ;OctoPrint pause
Pause G-code
@pause ;OctoPrint pause
After print job is paused
{% if pause_position.x is not none %}
; relative XYZE
G91
M83
; retract filament, move Z slightly upwards
G1 Z+5 E-1 F4500
; absolute XYZE
M82
G90
; move to a safe rest position, adjust as necessary
G1 X0 Y0
;disable all heaters
{% snippet 'disable_hotends' %}
{% snippet 'disable_bed' %}
;disable fan
M106 S0
{% endif %}
Before print job is resumed
{% if pause_position.x is not none %}
; relative extruder
M83
; Reset temperatures and fan
{% for tool in range(printer_profile.extruder.count) %}
{% if pause_temperature[tool] and pause_temperature[tool]['target'] is not none %}
{% if tool == 0 and printer_profile.extruder.count == 1 %}
M109 T{{ tool }} S{{ pause_temperature[tool]['target'] }}
{% else %}
M109 S{{ pause_temperature[tool]['target'] }}
{% endif %}
{% else %}
{% if tool == 0 and printer_profile.extruder.count == 1 %}
M104 T{{ tool }} S0
{% else %}
M104 S0
{% endif %}
{% endif %}
{% endfor %}
{% if printer_profile.heatedBed %}
{% if pause_temperature['b'] and pause_temperature['b']['target'] is not none %}
M140 S{{ pause_temperature['b']['target'] }}
M190 S{{ pause_temperature['b']['target'] }}
{% else %}
M140 S0
{% endif %}
{% endif %}
{% if pause_fanspeed is not none %}
M106 S{{ pause_fanspeed }}
{% endif %}
; prime nozzle
G1 E-1 F4500
G1 E1 F4500
G1 E1 F4500
; Extrude 20mm of filament
G1 E20
; absolute E
M82
; absolute XYZ
G90
; reset E
G92 E{{ pause_position.e }}
; WARNING!!! - use M83 or M82(extruder absolute mode) according what your slicer generates
M83 ; extruder relative mode
; move back to pause position XYZ
G1 X{{ pause_position.x }} Y{{ pause_position.y }} Z{{ pause_position.z }} F4500
; reset to feed rate before pause if available
{% if pause_position.f is not none %}G1 F{{ pause_position.f }}{% endif %}
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment