Octoprint: Conditional execution of commands

Hi!

Is there a way to have commands conditionally executed 'before the print starts'?

I am batch printing face shield supports and would like to have bed level calibration executed only every '5 prints' or so to save time, instead of every time if I use the 'before the print starts' section.
I find running it every time overkill, and running it manually generally means i forget to do it until i need to cancel mid-print due to bed adhesion issues.

Thanks!

I'm thinking that this could possibly help you.

Just guessing, but it might be something as easy as this in one of your Gcode startup scripts:

{% if time.localtime() is divisibleby 5 %}
G29
{% endif %}

Unfortunately, I don't think the GCODE scripts have any kind of iterable to keep track of number of prints. Maybe someone else will chime in here with a possible solution.

https://docs.octoprint.org/en/master/features/gcode_scripts.html#sec-features-gcode-scripts

Edit: @OutsourcedGuru's solution using time appears to be a possible alternative.

These run under the context of the Jinja templating. In theory, often-used JavaScript variables like this may be available. You'd have to test it, though.

That's what I was going to ask, because it seems that time is not defined as an option in the docs.

One could add a custom Snippet file (as a Jinja template) into the appropriate folder and call it by name. In that, in theory one could bring in whatever includes are required.

This could be done as plugin that keeps track of total prints since connect and provides the value to gcode scripts.