🇺🇦 We stand with Ukraine! 🇺🇦

Index of current layer from metadata


I need the index of current layer in my plugin. I found that I could calculate it from the layers data of the file analysis, what's not there by default. When I run the analyzer manually with "--layers" arg, I can see what I need.

Do you know why "--layers" arg is not added to analysis command of GcodeAnalysisQueue [1] by default?
What would be the best way to get layers info for every print inside a plugin?

I can rerun analysis with the extra arg from the plugin, but if you have a better idea, please tell.

Thank you,

[1] OctoPrint/analysis.py at 027d8f8069b86a7f5e8c185a2d8f294b631c2f08 · OctoPrint/OctoPrint · GitHub

There is a plugin called "DisplayLayerProgress", that provides couple of of ways to read the current layer of a print (via REST-API, EventBus or ViewModel). See readme for more details how to read the data.

Pretty sure that's not an option for the GcodeAnalysisQueue

or is it maybe included in PrintTimeGenius implementation? Only places I've seen layer number info is in the gcode viewer (calculated on the front-end js side) or lie OllisGit already mentioned, gleamed from his plugin.

GcodeAnalysisQueue executes this cli program [2] what accepts --layers as argument. My first question is: why is it not set in the command executed by GcodeAnalysisQueue?

My initial idea was that I could use the layers data to "lookup" the current layer index (~using current Z).

@OllisGit DisplayLayerProgress looks great (thank you for that!), unfortunately I cannot make our plugin depend on it, so using api/event bus is not possible in my case. Tracking gcode directly is another good idea, even if it looks more complicated at first sight.

[2] OctoPrint/analysis.py at b6ebe7c8539b86acb217483b853910d23518967f · OctoPrint/OctoPrint · GitHub

It was originally created as a debug option to compare the results with the gcode viewer's data about the file. If it was included in the analysis data saved with the file, it would result in the analysis result being huge, because there would be this set of data for every layer of the file. So it is not enabled, because it is not intended as useful data, only to debug/verify calculations done elsewhere.

Thank you for your answer.