🇺🇦 We stand with Ukraine! 🇺🇦

Read comments in GCODE during print - not included in handlers or events


I like to parse comments "; Blabla" during printing but the handlers like octoprint.comm.protocol.gcode.queuing or the events does not publish comments stored in the GCODE file. Does anybody know if it is possible to get comments of the line actually processed by OctoPrint?


OctoPrint doesn't process comments in gcode during a print. The only way to read them is to pre-process the actual file, and possibly replacing them with something else if that's what's necessary.

No, I need it during printing as I like to read out the remaining print time added by Cura. As a workaround I can add M117 but I like to build it with the standard comments.

If that it actually not possible I could perhaps add a new event in Cura itself. Does OctoPrint ignores comments in building the queue (that would be I expect…)? So perhaps I can add a event or hook there…

100% agree with @Charlie_Powell you'd have to setup a pre-processor in a plugin or react to the file added/selected event similar to how DisaplyLayerProgress plugin does.

One way around this would be using @ commands or action commands..

I spend some thoughts about it and it could be as follows:

Handler will be called if the command is queued which is not minutes away from the time the command is send to the printer?

And finished.... :slight_smile: Does @command interfere if the GCODE file is downloaded again and perhaps printed via SDCard. Did not know it before...

the @ command won't get processed by your printer and therefore not available with SD printing. Hooks — OctoPrint master documentation. You can get around that using M118 action/echo commands and then snagging it with the gcode received phase to act on to be more real-time information so replacing ;TIME_ELAPSED 123 with M118 TIME_ELAPSED 123 would then send back to the plugin the TIME_ELAPSED 123 bit...

An example of where I implemented the processing in Bed Level Visualizer using this method can be seen here.

1 Like

My plugin actually work with origin local only. But the commands are included in the GCODE file if somebody downloads it from OctoPrint? It will be ignored by Marlin?

E.g. Download the file via browser from OctoPrint, put it on an SDCard and put it in the printer...

Yeah, if they download the file from OctoPrint it will be the modified version post processing. Marlin will generally just ignore those I'm pretty sure so shouldn't be an issue.

1 Like

Hello, this is my first post. I actually searched for the same kind of issue raised in this post. When there is no way to have octoprint read scripts while printing, is there another way to have, for example, the nozzle wiped every 3 millimeter in Z? Or maybe whipe the nozzle at every pause? I have to learn a lot of things and this “break in” during printing would be very helpful if its possible. Thx.

you'd have to do that in slicer I think. closest thing I've seen to what your asking for was using the EasyServo plugin to perform the actions of moving the nozzle over to the side and wiping it with a bruch attached to servo on every layer change.

Yes. In cura its no problem to set it to wipe it at every layer. But im not sure it will improve the print by having the nozzle enter the print every layer from outside. I hoped to find a way to set it to wipe every 2 or 3 mm in Z height (every 10 layers?).

Its not that its impossible to pause the print and perform a nozzle wipe or some other action. Pressing pause does this.

Im going to edit the pause script to perform a nozzle wipe every time i press the pause button, but it would be so helpful if octoprint monitors the Z-height and pushes for this nozzle wipe every moment you want to have the nozzle cleaned.

For PETG its not a problem, for PLA it is. The amount of force when the nozzle hits a hard blob of PLA is too much