Layer Number and Total Layers from API


#1

Hi,

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.

Thanks,
Adi


#2

Job-based

https://docs.octoprint.org/en/master/api/job.html#retrieve-information-about-the-current-job

https://docs.octoprint.org/en/master/api/datamodel.html#sec-api-datamodel-jobs-progress

File-based

https://docs.octoprint.org/en/master/api/files.html#retrieve-a-specific-file-s-or-folder-s-information

https://docs.octoprint.org/en/master/api/datamodel.html#sec-api-datamodel-files-gcodeanalysis

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.


#3

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" http://octopi.example.com/api/job | jq -r ".progress.completion" | xargs printf "%.*f\n" 2

Adi