FLAP icon indicating copy to clipboard operation
FLAP copied to clipboard

KlipperScreen Load and Unload macros

Open Kaimberex opened this issue 1 year ago • 2 comments

I can't seem to get KlipperScreen unload and load buttons to trigger these macros manually. Has anyone gotten these to work with the built in load and unload buttons in KlipperScreen or do we need to just use the macro list to select the load and unload.

The error I get when pressing the built in klipperscreen buttons is:

!! Error evaluating 'gcode_macro UNLOAD_FILAMENT:gcode': jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'INDEX'

Kaimberex avatar Jan 28 '25 06:01 Kaimberex

I had the same issue. The Klippersceen native button does not pass an index parameter to the FLAP macro so it can't run. I did a workaround in flap_main.cfg where I use the default macro to launch the FLAP macros:

#KlipperScreen Hack
[gcode_macro UNLOAD_FILAMENT]
gcode:
filament_unload_init
  
[gcode_macro LOAD_FILAMENT]
gcode:
filament_load_init

gddhub avatar Jun 10 '25 01:06 gddhub

Here is my load and unload for FLAP and it works with KlipperScreen and FLAP. You need to add this to the _TEMP_VARIABLES macro: variable_last_index: 0


[gcode_macro LOAD_FILAMENT]
gcode:
  {% set last_idx = printer["gcode_macro _TEMP_VARIABLES"].last_index %}
  {% set index = params.INDEX|default(last_idx)|int %}
  SET_GCODE_VARIABLE MACRO=_TEMP_VARIABLES VARIABLE=last_index VALUE={index}
  {% set material = printer['gcode_macro _TEMP_VARIABLES'].materials[index] %}
  
  RESPOND TYPE=command MSG=action:prompt_end
  M117 Loading: {material[0]} (Index {index})
  M118 FLAP: Loading {material[0]} (Index {index})
  SET_GCODE_VARIABLE MACRO=_TEMP_VARIABLES VARIABLE=user_load_temp VALUE={material[1]} 
  SET_GCODE_VARIABLE MACRO=_TEMP_VARIABLES VARIABLE=user_min_load_temp VALUE={material[2]} 
  SET_GCODE_VARIABLE MACRO=_TEMP_VARIABLES VARIABLE=user_bed_temp VALUE={material[3]}
  SAVE_VARIABLE VARIABLE=user_load_temp VALUE={material[1]} 
  SAVE_VARIABLE VARIABLE=user_min_load_temp VALUE={material[2]} 
  SAVE_VARIABLE VARIABLE=user_bed_temp VALUE={material[3]}
  filament_load

[gcode_macro UNLOAD_FILAMENT]
gcode:
  {% set last_idx = printer["gcode_macro _TEMP_VARIABLES"].last_index %}
  {% set index = params.INDEX|default(last_idx)|int %}
  SET_GCODE_VARIABLE MACRO=_TEMP_VARIABLES VARIABLE=last_index VALUE={index}
  {% set material = printer['gcode_macro _TEMP_VARIABLES'].materials[index] %}
  
  RESPOND TYPE=command MSG=action:prompt_end
  M117 Unloading: {material[0]} (Index {index})
  M118 FLAP: Unloading {material[0]} (Index {index})
  SET_GCODE_VARIABLE MACRO=_TEMP_VARIABLES VARIABLE=user_load_temp VALUE={material[1]} 
  SET_GCODE_VARIABLE MACRO=_TEMP_VARIABLES VARIABLE=user_min_load_temp VALUE={material[2]} 
  SET_GCODE_VARIABLE MACRO=_TEMP_VARIABLES VARIABLE=user_bed_temp VALUE={material[3]}
  filament_unload

daredevilbear avatar Aug 04 '25 04:08 daredevilbear