Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vladbabii/97b66283369f46a092fe9e25e97a6dc8 to your computer and use it in GitHub Desktop.
Save vladbabii/97b66283369f46a092fe9e25e97a6dc8 to your computer and use it in GitHub Desktop.
klipper printer gcode incremental macro
#
# set start/end with gcode:
#
# SET_GCODE_VARIABLE MACRO=incremental_settings VARIABLE=start VALUE=2
# SET_GCODE_VARIABLE MACRO=incremental_settings VARIABLE=now VALUE=2
# SET_GCODE_VARIABLE MACRO=incremental_settings VARIABLE=end VALUE=5
#
# if you set now on each toolchange, if it runs out, the next tool will be used
#
# then run gcode:
#
# increment_next
#
[gcode_macro incremental_settings]
variable_now: 4
variable_start: 3
variable_end: 7
variable_step: 1
gcode:
GET_POSITION
[gcode_macro increment_next]
gcode:
{% set curr = printer["gcode_macro incremental_settings"].now|int %}
{% if curr < printer["gcode_macro incremental_settings"].start|int %}
{% set curr = printer["gcode_macro incremental_settings"].start|int %}
{% endif %}
M118 increment value is {curr}
{% if curr < printer["gcode_macro incremental_settings"].end|int %}
{% set now = printer["gcode_macro incremental_settings"].now|int+printer["gcode_macro incremental_settings"].step|int %}
M118 increment is set to new value: {now}
SET_GCODE_VARIABLE MACRO=incremental_settings VARIABLE=now VALUE={now}
{% if now == 5 %}
## do stuff here
M118 value is now 5
{% endif %}
{% if now == 6 %}
## do stuff here
M118 value is now 6
{% endif %}
{% if now == 8 %}
## do stuff here
M118 value is now 8
{% endif %}
{% else %}
## put code here when we reach the last tool / counter (stop printing?)
M118 increment would be too big
{% endif %}
@jhyland87
Copy link

Very useful. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment