This was mentioned a long time ago in this thread and perhaps elsewhere but it wasn’t ever built. Which I can hardly blame anyone because there is a learning curve that is not small.
I have been doing research into Octoprint plugins for my own top secret project, and I am now just barely competent at making plugins (watch out!).
Luckily, the default GCode Viewer is organized as a plugin already, so I was able to just copy the whole thing and change just about 5 lines of code to make it render CNC moves.
The basic idea is this: it keeps track of the lowest Z position it has ever seen, and if the tool is at that Z height, it is considered “extruding” and otherwise it is “not extruding”, i.e. traveling. That’s literally all there is to it. Oh and it recognizes “G00” and “G01” because Estlcam (and probably other CAM processors) generate these commands, but I guess 3D printing slicers never do.
So the modification itself is pretty minor, but ripping out the plugin and locating the five lines that need changing and repackaging was not trivial, at least not for me.
To install it, download the zip from github and within Octoprint’s plugin manager upload the zip file. I recommend disabling the default viewer (don’t need to fully remove), or the UI might get confusing.
I haven’t submitted this to the official Octoprint plugin repository. I guess I’ll do that next.
I asked about making a CNC option in the core Octoprint viewer, and foosel said it probably belonged in a plugin because it’s not useful for the bazillions of people that use octoprint for 3D printers (paraphrasing).
So I’ll proceed to go through the steps to submit the CNC GCode Viewer to the official plugin repository. Once it’s in the repository it will be just a few clicks away to drop it in. This also covers older installations, which a core patch wouldn’t address without an upgrade.
Well, kind of a bummer. I was hoping to avoid duplicating and maintaining all that gcode viewer code for a few small changes. But at least it is extensible enough to make the change in a plugin. Thanks for trying.
The Octoprint gcode viewer is a bit complex in that it tries to “understand” the gcode so it can render it nicely as layers. You would think for example that it might render an entire job with no extrusions as just a bunch of travel moves, but it doesn’t work that way. If it has no layers, it doesn’t show anything.
I haven’t tried it, but given the current approach of extruding only at the deepest Z, I’m guessing this will interfere with how it shows 3D carves and moves might not show up even as travel moves.
I just discovered there is a command M101 which is from some obsolete RepRap firmware that enables a continuous DC extruder. It doesn’t exist in Marlin. Octoprint does respect it and treats all movements as extrusions, so you could add that to the start of a 3D carve job, and it should render something.
That would make sense as an option, to render all moves as extrusions so M101 is not necessary in the gcode, or only render the deepest layers as extrusions and retain the light green color for travel moves and holding tabs.
For that matter, adding M101 would be all that would be necessary for the stock gcode viewer to work as-is, except for the bug that two-digit gcodes are not supported by the viewer: G00, G01, G02, and G03.
I skipped straight to submitting a PR to fix this bug, without first opening a discussion or issue about it.
Hopefully the patch is obvious enough that it can get merged without asking any questions about whether CNC support is “worth it”.