Best way to port my "wood plugin" to octoprint

I am the author of a very old python tool (https://www.wired.com/2012/11/3d-printer-wood-filament/) that generates/simulates wood stripes by changing the temperature along the Z axis: https://github.com/MoonCactus/gcode_postprocessors/tree/master/wood

It once was compatible with skeinforge and Cura (which kept breaking the plugins till I got fed up). So it is a now either a standalone python tool, or a webservice I host.

I kept being asked to port it as an OctoPrint plugin (which I don't use actually, shame on me).

I tried to make my mind around the very good documentation but I fail short to decide among various options:

  1. keep it a standalone (CLI) - eg. no work but no fun for the vast majority of users!
  2. add a standalone GUI on top of it (possible issues with packaging, support etc)
  3. write a small plugin to use my existing webservice (not sure I want to kill my server + configuration issues)
  4. decide which kind of octoprint plugin is best suited. I suspect a preprocessor or mixing is required. I guess the numerous options call for a specific tab in the UI.

The tool currently reads the whole gcode file and it overwrites it wit h temperature changes. One possible big issue is that it is not streamed (I think it will always need look-ahead), so it might require some non-obvious re-write of the algorithm.

Would you have an idea? Is there someone proficient with octoprint plugins who would like to contribute? May be it is just not suited to the usual plugins?

thanks all

I think I've used your script many moons ago when I was playing around with printing in wood. I think for your use case you might want to look into how the arc welder plugin is handling this. It is also a gcode post processor that can be used outside or inside of octoprint and might be a good jumping off point for you to convert the python script you already have.

What I would do if I were doing it from scratch would be to use the EventHandler mixin and utilize the Upload or FileAdded event hook in order to grab a handle on the file, do your processing, and save the file. I do like how arc welder gives you the option to save the file with a new name to not overwrite the original. I think the only other possible option would be using a file preprocessor hook in OctoPrint to grab as it comes in, but like you mention think that's a stream object, but you could save the file temporarily to the plugin's data folder, do what you need to do to the file and then return the file object. I've done this for my Cura Thumbnails and CustomBackground plugins.

2 Likes

In either case you're going to want to probably also use a settingsPlugin mixin to allow for setting the command line variables that you are defining now, which will allow for a UI within the settings interface of OctoPrint.

1 Like

Thanks for your knowledgable help. And your second post responds to the question that I had in mind while reading your first one :wink: You are right about Arc Welder, it seems to be the best candidate to focus on - I previously missed the fact that it even had a setting panel within octoprint, ie. all what I need.
Thanks again :slight_smile:

Arc welder is a little more complicated than this probably needs to be, since it does all sorts of fancy things including welding the curves together. If you haven't already, check out the plugin tutorial (below) and the plugin docs. If you already understand Python/HTML/JS then you will be fine, the only thing that can be a massive pain if you've never used it is Knockout in the UI. But we can cross that bridge when it we get there.

Thanks, yes, I parsed them before asking :wink:
I am not fluent enough in "modern" web development nor python to do it quickly. I could hack my way out of anything but I would better remove code from something than merge two examples and build upwards, lazy as I am (I mostly write algorithms and/or hairy low level stuff, and mostly C/C+/java/shell).
Eg. I never heard of Knockout so far. Even though I am pretty curious, I would better invest time in Svelte first (and honestly, better understand JS paradigms in the first place). But as you say that can be done in a subsequent step :slight_smile:
I'll give it a second try, I have two days left of holidays :stuck_out_tongue: