Help with start print macro

Basic Information:

Printer Model: Ender 3 V2
MCU / Printerboard: Creality 4.2.2
klippy.log (5.3 MB)
klippy.log

Fill out above information and in all cases attach your klippy.log file. Pasting your printer.cfg is not needed
When pasting code or config snippets use the code tags </> in the menu above

Describe your issue:

I setup a basic start print macro based on what I found on the Klipper config reference. However I’m always getting the following error:

Error evaluating ‘gcode_macro PRINT_START:gcode’: jinja2.exceptions.UndefinedError: ‘dict object’ has no attribute ‘heater_bed’

I’m also getting “Unknown command” for M201, M203 and M205 which apply to accel settings but I don’t know how to turn off accel in my slicer (PrusaSlicer)

I’m pretty sure that parameter names need to be specified in upper case, so try “params.HEATER_BED” and see if that works.

Nope, now the error just has HEATER_BED instead of heater_bed lol. In the top part of the config where it sets up the steppers and such it is in there as “heater_bed”.

I got rid of the M command errors though, switched the slicer from Marlin to RepRap/Sprinter.

Can you give an example how you call the PRINT_START macro? I’d recommend to define such as float otherwise you would have to make sure not to accidentally pass 60.0 to the macro.

And @jrobbom5 is right, the params need to be upper-case, i.e.

[gcode_macro PRINT_START]
gcode:
	{% set heater_bed = params.HEATER_BED|float %}
	{% set extruder = params.EXTRUDER|float %}
1 Like

This is how it is currently in my config file:

[gcode_macro PRINT_START]
#USE PRINT_START FOR THE SLICER STARTING SCRIPT
gcode:
  #parameters
  {% set heater_bed = params.HEATER_BED|int %}
  {% set extruder = params.EXTRUDER|int %}
  M140 S{heater_bed}
  G90 # Set absolute positioning
  G28 # Home all axes
  M190 S{heater_bed}
  # Sit and wait for nozzle to reach temp
  M109 S{extruder}

changing the “int” to “float” didn’t do anything, same error

Ok so I basically copied this sample (minus the move close to bed part because I like to pull off the ooze): klipper/sample-macros.cfg at master · Klipper3d/klipper · GitHub

So now my start code is this:

[gcode_macro PRINT_START]
#USE PRINT_START FOR THE SLICER STARTING SCRIPT
gcode:
  #parameters
  {% set BED_TEMP = params.BED_TEMP|float %}
  {% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|float %}
  M140 S{BED_TEMP}
  G90 # Set absolute positioning
  G28 # Home all axes
  M190 S{BED_TEMP}
  # Sit and wait for nozzle to reach temp
  M109 S{EXTRUDER_TEMP}

And I’m STILL getting the exact same error, now with BED_TEMP in place of HEATER_BED:

Error evaluating 'gcode_macro PRINT_START:gcode': jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'BED_TEMP'

Ok so I literally copy/pasted this from the examples:

[gcode_macro START_PRINT]
gcode:
    {% set BED_TEMP = params.BED_TEMP|default(60)|float %}
    {% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(190)|float %}
    # Start bed heating
    M140 S{BED_TEMP}
    # Use absolute coordinates
    G90
    # Reset the G-Code Z offset (adjust Z offset if needed)
    SET_GCODE_OFFSET Z=0.0
    # Home the printer
    G28
    # Move the nozzle near the bed
    G1 Z5 F3000
    # Move the nozzle very close to the bed
    G1 Z0.15 F300
    # Wait for bed to reach temperature
    M190 S{BED_TEMP}
    # Set and wait for nozzle to reach temperature
    M109 S{EXTRUDER_TEMP}

I changed “START_PRINT” to “PRINT_START” and it worked. No errors. Gotta remove the drop Z to 0.15 part though and for some reason it was at temp (215) then dropped to 190, then back to 215 and started printing

I’m having this issue too and im pretty sure its a macro thing but i can’t figure it out too . Ive tried cura / prusaslicer both with START_PRINT / END_PRINT .

Theres probably a way to get the actual gcode file temp instead of resetting the Extruder temp .

Here’s mine :
####################################################################
[gcode_macro START_PRINT]
gcode:
{% set BED_TEMP = params.BED_TEMP|default(90)|float %}
{% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(240)|float %}
# Start bed heating
M140 S{BED_TEMP}
# Use absolute coordinates
G90
# Reset the G-Code Z offset (adjust Z offset if needed)
SET_GCODE_OFFSET Z=0.0
# Home the printer
G28
BED_MESH_CALIBRATE
# Move the nozzle near the bed
G1 Y10 X10 Z0.28
# Move the nozzle very close to the bed
G1 Z0.15 F300
# Wait for bed to reach temperature
M190 S{BED_TEMP}
# Set and wait for nozzle to reach temperature
M109 S{EXTRUDER_TEMP}
M117 PRIME LINE
G92 E0 ; Reset Extruder
# Move to Prime position
G1 Y10 X10 Z0.28 F5000.0 ; Move to start position
G1 Y200 X10.0 Z0.28 F1500.0 E15 ; Draw the first line
G1 Y200 X10.5 Z0.28 F5000.0 ; Move to the side a little
G1 Y10 X10.5 Z0.28 F1500.0 E30 ; Draw the second line
G92 E0 ; Reset Extruder
G1 Z2.0 F3000 ; Move Z axis up
G1 Z0 F3000 ;
G1 Z0.2 F100
#BED_MESH_PROFILE LOAD=default
####################################################################

Btw i apologize for all the people who will read this huge block of text .

Best Regard

*Printer Model: Ender 3 V2
MCU / Printerboard: Creality 4.2.2
Microswiss Direct Drive ( dont buy it , its outdated xD )

OK, so the obvious difference that I can see between what you had, and the macro that worked, is that the one that worked sets a default value for BED_TEMP if it is not specified. This leads me to believe that when you are calling the macro, presumably from your slicer, that there is something wrong with the BED_TEMP parameter, like it is misspelled, or you are using “-” instead of “_” etc.

If you can post the line from your slicer where you call the PRINT_START macro, we may be able to help you figure it out

Please post the line from your slicer where you call the macro, just so that I can see what it going on. :slight_smile:

Hey I have a question regarding a similar problem. Can I post here my stuff or should I prepare a new post?

For the age of this thread, please open a new one. Thank you!