Octoprint CNC GCode Viewer

I made a thing!

This time it’s an Octoprint plugin https://github.com/vector76/cnc_gcodeviewer :

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.

17 Likes

So true.

I wonder if you could convince Foosel to add a button for CNC mode on the gcode preview and get it merged upstream.

1 Like

Not a bad idea, or alternatively I could envision it in the settings. I will ask.

1 Like

Wow, impressive!

1 Like

That’s what I was thinking. I think that is a great idea.

2 Likes

Making headless better, Thank you!

1 Like

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.

4 Likes

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.

1 Like

I was looking at the description, how does this handle a 3D carve? Is it easier to show all moves except G0?

I really need to poke around with octoprint again, your plug in started the rabbit hole of discovery.

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.

2 Likes

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”.

2 Likes

Update, now, with version numbers!

v1.0.1 uses “replaces-viewmodel” approach so the native gcode viewer doesn’t have to be disabled. The CNC GCode Viewer just replaces the tab in place.

The latest is available here:
(https://github.com/vector76/cnc_gcodeviewer/archive/main.zip)
Or a particular release can be had here:
(https://github.com/vector76/cnc_gcodeviewer/archive/refs/tags/v1.0.1.zip)

The plugin has also been submitted to the plugin repository and it’s working its way through the process:
(https://github.com/OctoPrint/plugins.octoprint.org/pull/1025)

3 Likes

And merged! :tada:

Meaning it’s easily accessible from the plugin repository.

That’s all for now.

8 Likes

Congrats, I can say, you will most likely never see anything with my name on it for such an item!

Must feel good!

2 Likes

I love that the preview image has the test crown:

I am curious to see how this works with the sand table, and with sandify plots. I bet it would work.

3 Likes

Awesome! And your twitter famous.

3 Likes