Trouble with [save_variables] on 2.0

In previous ratOS I had a couple of macros for adjusting my z-offset between smooth and textured plate using a variables.stb file. I just upgraded to 2.0 and am getting errors when trying to use the macros. My macros are as follows:
filename: /home/pi/klipper/config/variables.stb

[gcode_macro SMOOTH_PLATE]
gcode:
{% set value = printer.save_variables.variables.smooth %}
SAVE_VARIABLE VARIABLE=active_offset VALUE={value}
{action_respond_info("Smooth sheet active with offset %.3fmm" % (value))}
[gcode_macro TEXTURED_PLATE]
gcode:
{% set value = printer.save_variables.variables.textured %}
SAVE_VARIABLE VARIABLE=active_offset VALUE={value}
{action_respond_info("Textured sheet active with offset %.3fmm" % (value))}
[gcode_macro APPLY_PLATE_OFFSET]
gcode:
{% set active_offset = printer.save_variables.variables.active_offset %}
SET_GCODE_OFFSET Z={active_offset} MOVE=1
{action_respond_info("Current Z offset %.3fmm" % (active_offset))}
filename: /home/pi/klipper/config/variables.stb

[gcode_macro SMOOTH_PLATE]
gcode:
{% set value = printer.save_variables.variables.smooth %}
SAVE_VARIABLE VARIABLE=active_offset VALUE={value}
{action_respond_info("Smooth sheet active with offset %.3fmm" % (value))}
[gcode_macro TEXTURED_PLATE]
gcode:
{% set value = printer.save_variables.variables.textured %}
SAVE_VARIABLE VARIABLE=active_offset VALUE={value}
{action_respond_info("Textured sheet active with offset %.3fmm" % (value))}
[gcode_macro APPLY_PLATE_OFFSET]
gcode:
{% set active_offset = printer.save_variables.variables.active_offset %}
SET_GCODE_OFFSET Z={active_offset} MOVE=1
{action_respond_info("Current Z offset %.3fmm" % (active_offset))}
and the variables.stb file is simple:
active_offset = 0.0
smooth = 0.0
textured = -0.335
active_offset = 0.0
smooth = 0.0
textured = -0.335
The error I get when trying to select my plate is:
Error evaluating 'gcode_macro SMOOTH_PLATE:gcode': jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'smooth'
Error evaluating 'gcode_macro SMOOTH_PLATE:gcode': jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'smooth'
Any help would be great! Or if there is a better build in way to do this now that would be awesome too!
3 Replies
miklschmidt
miklschmidt•2y ago
That's because save variables doesn't work unless the file is present on the system. Just create variables.stb in /home/pi/printer_data/config/variables.stb, and change the filename under [save_variables] to reflect the path. That path was never valid in the first place. ie you want:
[save_variables]
filename: /home/pi/printer_data/config/variables.stb
[save_variables]
filename: /home/pi/printer_data/config/variables.stb
Rubby
RubbyOP•2y ago
Ah I did have the variables.stb present in the config folder but yes I had the directory wrong. I have changed the path under [save_variables] and it works! Thanks for the quick fix!
miklschmidt
miklschmidt•2y ago
you're welcome! 🙂
Want results from more Discord servers?
Add your server