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

Hi,

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?

Cheers,
Nils

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

I implemented a first version with hook octoprint.filemanager.preprocessor to add AT commands and it works very fine. Before I used the FILE_ADDED event but then the file is available a short time in old format. I ask me if I can do all file scanning in the preprocessing also which would save time but as the file is not copied to the final folder I am not sure if the metadata should be set at that step.

What I like to do:

  1. pre-process file and change the content - gather metadata information also in that step as all lines are read...
  2. write the extracted information to file metadata. ; But what would be the best step to store metadata with set_additional_metadata to the file? Still the FILE_ADDED event as in the pre-processing hook I cannot write it. I am afraid if the user is "fast" he can upload the next file before everything is stored...

preprocessor probably works prior to analysis, but you could probably move your process into a octoprint.filemanager.analysis.factory hook and do it all at the same time.

Done it like bedvisualiser and get it working to gather all data during the file upload as from my point of view an optimal solution. :smile:

For that I created some more classes and now like to use the octoprint logger in that. I can pass it via a parameter during init from plugin class but perhaps there is a better way.

This is not working in the class:
OctoPrint-BedLevelVisualizer/octoprint_bedlevelvisualizer at b5721d1de83d92f1ef77dcc103f0931b704462d0 · jneilliii/OctoPrint-BedLevelVisualizer · GitHubinit.py#L42

If it's another class outside of the plugin's then you have to pass a plugin object to that separate class and use its logger I think. I believe I've seen this with the simply print plugin.

Ok, that would be similar to pass the logger only. Checked the simply print plugin plugin but it has one class only. But anyhow, if that is a good solution to pass the logger (or plugin class) it is fine.

Actually looking at their websocket rewrite branch is seems they're doing it the same way you were.