Is it possible to customize the PRINT and RESUME button behaviour? (using the "loaded file variable"))

What is the problem?

Because of klipper I want to customize the commands used to start and resume a print.

In the first case I need to use the commands:

M23
M24

Because in klipper I want to use the print_stats and this forces me to print from the virtual SD card.

What did you already try to solve it?

The octoklipper plugin already allows to create custom buttons, this fixed the RESUME button problem.

I have been reading about custom controls, but still I don't know how to retrieve the "loaded file" variable in order to use the custom gcode.

Even if possible with custom controls it would be mi least preferred solution.
1 Edit PRINT button.
2 Use octoklipper macro.
3 Custom control.

But right now everything revolves around using the "loaded file" within one of these solutions.

Have you tried running in safe mode?

It does not apply to my question.

Did running in safe mode solve the problem?

It does not apply to my question.

Systeminfo Bundle

octoprint-systeminfo-20250102112228.zip (135.3 KB)

Additional information about your setup

My setup is a CR10 S4 with a BTT SKR2.0 board.
Klipper running in a RPI4.
Evrything works as expected, and I'm just fine tuning a couple of things

Klipper has it's own pause/resume macros:

https://www.klipper3d.org/G-Codes.html#pause_resume

Why use others?

Anyhow, you can create Klipper macros that redirect M24/M25 to the Klipper pause/resume commands.

That's my point I want to map the octoprint buttons to klipper macros.

The RESUME klipper command is somehow different from the resume button, and I don't know the reason that's why I want to change the resume button in octoprint to call RESUME macro.

Same goes for the start (print button). It is different than start from SD (M24). And I need the start from SD because I'm using the printer.print_stats.filament_used value in order to delay the runout pause.

OctoPrint automatically use M23/M24 commands if you are printing printer "SD card" files. When you upload files to OctoPrint are you uploading to SD card (button on right)?

@jneilliii Apologies I forgot to mention this. If use the upload to SD card in octoprint it gives an error about "can't write the SD card". But this is expected because the documentation already says:

#   The path of the local directory on the host machine to look for
#   g-code files. This is a read-only directory (sdcard file writes
#   are not supported).

Anyhow I can see all my uploaded files (regular upload, NOT upload to SD). I can list all the files with M20, select file (M23) and print (M24).

Therefore my guess is that I want to trick octoprint to use the uploaded files as if they were uploaded to SD card.

We are at the initial point again. How to customize the print button behavior, or have a custom button, and how to capture the loaded file as a variable to use in my custom code.

Don't mix up the SD card in the printer with the virtual SD card of Klipper. They do not work the same.

Configuration reference - Klipper documentation.

That's the reason you cant use OctoPrint's M24/M25 with Klipper

Can you develop further? Why I cannot use M24 with klipper? I'm already using it and it is already in the documentation.

https://www.klipper3d.org/G-Codes.html?h=virtual_sdcard#virtual_sdcard

Some Virtual SD card features of Klipper do not work with OctoPrint, they work with Mainsail/Fluidd via Moonraker.

For further information, you may ask here:

I agree, and yes, moving to mainsail was in my mind since I moved to klipper. Just kept octoprint because I'm familiar with it.

Anyhow I want to confirm what options do I have in octoprint/octoklipper. A simple (on paper of course) solution for me would be creating the macro in octoklipper, but I do need to know if I can capture the octoprint loaded filename.

I think the better question is what does print_stats get you in klipper that you aren't able to accomplish with some other plugin?

Some information you only can get via the Klipper API, not via the (virtual) serial port.

@jneilliii The key pramater is printer.print_stats.filament_used.

I use it to delay the filament replacement MACRO when the runout sensor triggers. If there is another way to keep track of the used filament that would make my life easier.

pretty sure filament manager and spool manager plugins track usage.

If I read it correctly the approach is completely different.

Those plugins just keep track of the used filament regardless of any feedback from the filament sensor.