NUM_LAYERS in G-code
I've seen some posts here about the number of layers being incorrect, and I'm having the same problem. It seems that if there is a comment in the G-code file like the following:
then it will use that for the total number of layers. Though in testing, that does not seem to be a thing. I've tried with firmware 3.3.0 and also 3.4.0-rc1. In general, it simply takes the last Z move, divides it by the layer height that it thinks is being used, and uses that as the number of layers. This does not work because I move the head up by a bit at the end of the print to avoid crashing into the print, and also some prints have variable layer sizes.
Another issue is that when running a second print, it will not update the total layer count. So if I print one file with 100 layers, and then a second file with 200 layers, during the entirety of the second print, it will read "Layer X of 100".
Here's a simple file demonstrating the problems: Shape-Box.gcode. This file specifies the number of layers as 50, yet it says 53 layers the entire time. Additionally, if I then print a cube that is twice as bit (with 100 layers), it will still say there are 53 layers until I refresh the interface, then it will update to 103.
Actually, after looking at https://github.com/Duet3D/RepRapFirmware/blob/51e5b27066627850a8c9d55bf14c6fe656c7af70/src/Storage/FileInfoParser.cpp, it looks like the NUM_LAYERS comment is only checked in the file footer, and I was including this at the top of the file.
dc42 administrators last edited by
@vcapra1 some slicers use variable layer height. I think that is why RRF only looks for NUM_LAYERS in the footer, because the slicer may not know the number of layers until the end. If you find any slicers that put that comment or a similar one at the start by default, let us know.
@dc42 That makes sense. PrusaSlicer can put it in at the beginning using custom g-code (which is what I was doing), but it doesn't by default. So I agree it's better to check just the end. Thanks for your reply!