[solved] Executing gcode from a file?

I have a first-layer calibration gcode file I like to run to set the Z offset. It’s just a 60mm square printed at 0.2mm layer height. The only difference between using it for ABS vs PLA is the temperature; I’d want to use the filament I have loaded at the moment, rather than reload with a specific filament just for getting the squish right.

I’m imagining modifying the gcode file to remove the commands to set temperature, and then printing the file. I really don’t want to include the entire gcode file inline in a macro definition, so I’m wondering if it’s possible within a macro to open a file and print it, or just do the equivalent of a #include from within the macro source?

Why do you want the gcode file included in your config? Couldn’t you just leave the file on the printer, set the temperature to whatever you need, and select the file to print once it’s at temperature?

Just so that I can call FIRST_LAYER_CALIBRATION EXT_TEMP=245 BED_TEMP=100. What you’re suggesting is totally doable, but I’d still like to know if I can do it my way. :grinning:

You should be able to do it with a macro that calls M23 to load the file, and M24 to start the print.

https://www.klipper3d.org/G-Codes.html#g-code-sd-card-commands

Oh, brilliant! Thank you!

This is my working solution. Thanks to @jakep_82 for the tips. Note that M23 doesn’t know what to do with subdirectories, so my first attempt with M23 calibration/first… didn’t work, but moving the file and changing the path did. Awesome!

[gcode_macro FIRST_LAYER_CALIBRATION]
gcode:
    {% set EXTRUDER_TEMP = params.EXTRUDER | float %}
    {% set BED_TEMP = params.BED| float %}

    M23 calibration_first_layer_no_temp.gcode
    PRINT_START EXTRUDER={ EXTRUDER_TEMP } BED={ BED_TEMP }
    M24