Macro referencing variable and then updating that variable

Can someone tell me why my “adjust” parameters are not working? I know jinja has some weirdness with how macros are evaluated in full before execution but I can’t figure out what the exact problem is:

[gcode_macro set_separation]
gcode: 
    {% set svv = printer.save_variables.variables %}

    {% set oldX = svv.xoffset|float %}
    {% set oldY = svv.yoffset|float %}
    {% set oldZ = svv.zoffset|float %}

    {% if params.X is defined %}
        SAVE_VARIABLE VARIABLE=xoffset VALUE={ params.X|float }
    {% endif %}

    {% if params.Y is defined %}
        SAVE_VARIABLE VARIABLE=yoffset VALUE={ params.Y|float }
    {% endif %}

    {% if params.Z is defined %}
        SAVE_VARIABLE VARIABLE=zoffset VALUE={ params.Z|float }
    {% endif %}

    {% if params.X_adjust is defined %}
        {% set newX = params.X_adjust|float + oldX %}
        SAVE_VARIABLE VARIABLE=xoffset VALUE={ newX|float }
    {% endif %}

    {% if params.Y_adjust is defined %}
        {% set newY = params.Y_adjust|float + oldY %}
        SAVE_VARIABLE VARIABLE=yoffset VALUE={ newY|float }
    {% endif %}

    {% if params.Z_adjust is defined %}
        {% set newZ = params.Z_adjust|float + oldZ %}
        SAVE_VARIABLE VARIABLE=yoffset VALUE={ newZ|float }
    {% endif %}

From my understanding you have to always use upper-case for params.*, ie params.Y_ADJUST, not params.Y_adjust, etc.

From the manual: “Note that parameter names are always in upper-case when evaluated in the macro and are always passed as strings.”

You’re awesome! That worked!

Hi, please help me. I’m a newbie at klipper. I’ve conveerted a Idex cartesian to klipper and i’m trying to get it work.
I’ve seen a loto of macros on the net and this seems one of the most useful.
but when i try to use it i get this errors:

> Error evaluating 'gcode_macro set_separation:gcode': jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'xoffset'

Because of the age of this thread I recommend to open a new thread with all requested information.

after some hour diggin’ the treasure has been found!..
I was not writing variables in the save variable file…
everything workin’ fine. thanks for sharing knowledge