Template syntax error

Basic Information:

Printer Model: flying bear reborn 2
MCU / Printerboard: MKS robin nano 3.2? (Typing in MKS nano 6 should bring it up as well)
klippy.log

Fill out above information and in all cases attach your klippy.log file. Pasting your printer.cfg is not needed
Be sure to check our Knowledge Base and in particular this and this post

Describe your issue:

I’m getting a template syntax error with this macro, saying a name or number was expected, you can see what I have below.

[gcode_macro _get_pos]
variable_x: 0
variable_y: 0
variable_z: 0
gcode:
{% set X_pos = printer.[gcode_move, gcode_position].x %}
{% set Y_pos = printer.[gcode_move, gcode_position].y %}
{% set Z_pos = printer.[gcode_move, gcode_position].z %}
SET_GCODE_VARIABLE MACRO=_get_pos VARIABLE=x VALUE{X_pos}
SET_GCODE_VARIABLE MACRO=_get_pos VARIABLE=y VALUE{Y_pos}
SET_GCODE_VARIABLE MACRO=_get_pos VARIABLE=z VALUE{Z_pos}


klippy.log (115.0 KB)

In this case, could you please share the printer.cfg?

you need to do SET_GCODE_VARIABLE MACRO=_get_pos VARIABLE=x VALUE={X_pos} instead of SET_GCODE_VARIABLE MACRO=_get_pos VARIABLE=x VALUE{X_pos} (and for y and z the same ofc)

the contents of the printer.cfg are in the log so you can just look them up there

@LastZeanon
I know that well.

But some errors are not transferred into the parsed klippy.log version.

Fixed that after I noticed :grin:

This is in a separate file from my main config, which works fine as I used it for about 8 months. Do you need the contents of the file it’s in? Either case that might be a bit I have an electrician at my house right now

1 Like

If it works now, it is fine.

Sometimes there dependencies that can raise problems fir the configs are ins separate files.

For example: TMC sections should be in the same config whare the stepper sections are. One reason: The TMC sections need the microstep setting that is in the stepper section.

ok well here’s every macro in the file the one giving the error is in, sorry if they’re different block quotes but I usually separate my macros by a line and it doesn’t translate well to discourse

[gcode_macro _get_pos]
variable_x: 0
variable_y: 0
variable_z: 0
gcode:
    {% set X_pos = printer.[gcode_move, gcode_position].x %}
    {% set Y_pos = printer.[gcode_move, gcode_position].y %}
    {% set Z_pos = printer.[gcode_move, gcode_position].z %}
    SET_GCODE_VARIABLE MACRO=_get_pos VARIABLE=x VALUE={X_pos}
    SET_GCODE_VARIABLE MACRO=_get_pos VARIABLE=y VALUE={Y_pos}
    SET_GCODE_VARIABLE MACRO=_get_pos VARIABLE=z VALUE={Z_pos}

[gcode_macro _zone_vars]
variable_zone_xy: 0
variable_zone_z: 0
variable_zone_delta: 0
variable_zone_x: 0
variable_X_max: 325
variable_Y_max: 325
variable_Z_max: 350
gcode:

[gcode_macro _set_zone_core_xy]
gcode:
    {% if [gcode_macro, _get_pos].x >=0 and < [gcode_macro, _zone_vars].X_max / 2 and [gcode_macro, _get_pos].y >=0 and < [gcode_macro, _zone_vars].Y_max / 2 %}
        SET_INPUT_SHAPER SHAPER_TYPE=ZV SHAPER_FREQ_X=50 SHAPER_FREQ_Y=50
    {% else if [gcode_macro, _get_pos].x >= [gcode_macro, _zone_vars].X_max / 2 and [gcode_macro, _get_pos].y >=0 and < [gcode_macro, _zone_vars].Y_max / 2 %}
        SET_INPUT_SHAPER SHAPER_TYPE=ZV SHAPER_FREQ_X=100 SHAPER_FREQ_Y=100
    {% else if [gcode_macro, _get_pos].x >=0 and < [gcode_macro, _zone_vars].X_max / 2 and [gcode_macro, _get_pos].y >= [gcode_macro, _zone_vars].Y_max / 2 %}
        SET_INPUT_SHAPER SHAPER_TYPE=ZV SHAPER_FREQ_X=150 SHAPER_FREQ_Y=150
    {% else if [gcode_macro, _get_pos].x >= [gcode_macro, _zone_vars].X_max / 2 and [gcode_macro, _get_pos].y >= [gcode_macro, _zone_vars].Y_max / 2 %}
        SET_INPUT_SHAPER SHAPER_TYPE=ZV SHAPER_FREQ_X=200 SHAPER_FREQ_Y=200



[gcode_macro G0]
rename_exsisting: G0.1
gcode:
    _get_pos
    _set_zone_core_xy
    G0.1 {rawparams}

[gcode_macro G1]
rename_exsisting: G1.1
gcode:
    _get_pos
    _set_zone_core_xy
    G1.1 {rawparams}
1 Like

@nathan22211 .

One tiny request: Can you please put the code snippets between the appropriate braces:

Format

Without that, the format is messed up and important spaces are gone.

ok made that edit, still learning how discorse does formatting… I’m more used to HTML or Markdown

1 Like

Don’t suppose you have any insight into this error? Because I have no clue what’s causing it

Try it like this:

[gcode_macro _get_pos]
variable_x: 0
variable_y: 0
variable_z: 0
gcode:
  {% set X_pos = printer.gcode_move.gcode_position.x %}
  {% set Y_pos = printer.gcode_move.gcode_position.y %}
  {% set Z_pos = printer.gcode_move.gcode_position.z %}
  SET_GCODE_VARIABLE MACRO=_get_pos VARIABLE=x VALUE{X_pos}
  SET_GCODE_VARIABLE MACRO=_get_pos VARIABLE=y VALUE{Y_pos}
  SET_GCODE_VARIABLE MACRO=_get_pos VARIABLE=z VALUE{Z_pos}

Are you trying to do a dynamic input shaper?
If so, could you elaborate on how you defined the zones and stuff, would be quite interesting imo

Check my topic in general called dynamic input shaper. I’m currently running tests to see how well it works