Layer Number and Total Layers from API



Is it possible to get the current printing layer number and the total number of layers from the OctoPrint API.

I am working on an external streaming "thing" that will display some information as text overlay. I would like some sort of progress information. From reading API docs I can see that there is a progress percentage available that is based on the gcode file size. Just wondering if layer numbers are also available.





I've not seen layers or current layer as present within this interface. An event called ZChange is fired off for layer change, which may be useful.

Within the underlying OctoPrint Python-based model appears to be currentZ which is the Z height in mm; assuming you know the layer height, you could calculate the current layer.


Thank you! I think my best bet for now is to simply settle for progress as calculated and presented by the API. Rounded to 2 digits I can do:

curl -s -H "X-Api-Key: REDACTED" | jq -r ".progress.completion" | xargs printf "%.*f\n" 2