Generate wood patterns with temperature changes

by MoonCactus, published

Generate wood patterns with temperature changes by MoonCactus Feb 11, 2013


Liked By

View All

Give a Shout Out

If you print this Thing and display it in public proudly give attribution by printing and displaying this tag.

Print Thing Tag

Thing Statistics

34523Views 3547Downloads


Script to generate texture via temperature gradients to get horizontal stripes that "look like wood". The last and only updated source code is now on github at https://github.com/MoonCactus/gcode_postprocessors/tree/master/wood

The owl is Cushwa's popular design at http://www.thingiverse.com/thing:18218

It was printed here with LAYWOO-D3 wood filament http://www.thingiverse.com/thing:30552
It works also somehow with some other filament (just tweak the temperature), with a less drastic effect.

This is a piece of source code of mine, originally made for Skeinforge within Cura 12.08, now part of the official releases, and is now also an independent standalone Python script.


Download the python script from https://github.com/MoonCactus/gcode_postprocessors/tree/master/wood
This script was designed and works with Python 2.X, it may have some issues with Unicode and Python 3.

Installation: move the .py file to the plugin folder in Cura (like /usr/share/cura/plugins or ~/.cura/plugins/). The Ultimaker website does not tell which one really, but look with your file manager for a folder named "plugins", or better, for a plugin which is shipped by default (e.g. TweakAtZ.py). Then simply copy/paste this file alongside, and restart Cura.

This is the code of my post here: http://betterprinter.blogspot.fr/2012/10/shades-of-brown-with-wood-filament-via.html

Last updates:
Wed Mar 29 18:53:31 CEST 2017
Moved to github! This is the terminal update that will appear here!
Wed Sep 28 12:41:55 CEST 2016
Instructions cleanup and cosmetic fix to the python script
Fri Jan 10 14:32:52 CET 2014
wood31 Fixed obsolete syntax that made Python3 fail (thanks @Mysli)
wood32 is for Python3, should work also on Python2 but untested by me!
Thu Jan 9 23:10:51 CET 2014
Added some more options, and a Windows-friendly zipped version with windows line ends and zipped so that it does not get corrupted when downloaded or opened (this OS sucks so much that you have to pay for it, and you get a notepad as useful as an ashtray on a motorbike, so ridiculous!)

Sun Jul 7 21:43:12 UTC 2013

  • there is a limited web service hosted on https://www.tecrd.com/tools/stl_wood (but it may refuse your file because it is too big, or because the server is busy doing something else)
    Tue Feb 12 08:35:53 UTC 2013
  • more readable ASCII art plot
  • can be re-run on itself, it will no more duplicate the commands and graph
  • fixed a bug in the numeric arguments (thanks to Fused3D)

This script was an official plugin in Cura (version 12.11+). But the support for Cura at Ultimaker is gone for years now (why?).

After multiple requests and at last, I finally converted it to a standalone Python script that no more needs Cura nor Skeinforge. I documented the process here by the way: http://betterprinter.blogspot.fr/2013/02/how-tun-run-python-cura-plugin-without.html

You'll need Python 2.7 on your computer. Then run the wood.py script as follows:

python wood.py --min minTemp --max maxTemp --grain grainSize --file gcodeFile

or in brief mode:

python wood.py -i minTemp -a maxTemp -g grainSize -f gcodeFile

This will "patch" your gcode file in place (it will be modified), so keep a backup if you need one.

  • minTemp(float:180) Minimum print temperature (degree C)
  • maxTemp(float:230) Maximum print temperature (degree C)
  • grainSize(float:3.0) Average "wood grain" size (mm)
  • firstTemp(float:0) Starting temperature (degree C, zero to disable)
  • spikinessPower(float:1.0) Relative thickness of light bands (power, >1 to make dark bands sparser)
  • maxUpward(float:0) Instant temperature increase limit, as required by some firmwares (C). In some case they would seemingly stop the printer because of the thermal inertia of the head (no harm really, it only uselessly triggers a safety in the firmware). You may get fuzzier transitions from light to dark when you use this option.
  • zOffset(float:0) Vertical shift of the variations, as shown at the end of the gcode file (mm)

The gcodeFile is the only compulsory parameter. Check the source code for more information.

Initial temperature settings will be overridden by the varying pattern that is generated by this script (a variant of recursive Perlin noise). You can run it multiple times to test different values and generated temperature curve until you like it.

Default values are minTemp=190, maxTemp=240 and grainSize=3. Higher themperature give darker bands (due to the wood being burnt). Do not let the wood stay too long in your nozzle else you will most probably clog it with carbon!

Finally, to run it on windows you may want to check the FAQ here: http://docs.python.org/2/faq/windows.html

All Apps

Upgrade this Thing with Thingiverse Apps

No results.

6 days ago - Modified 6 days ago

I guess MoonCactus killed the webpage supporting the script.

6 days ago - Modified 5 days ago
MoonCactus - in reply to Necromantia

It got axed as a collateral damage when I eventually updated my main site a few days ago, but it is back now :)

Comments deleted.

IMHO you checked all the obvious possible cause. Black filament often have "special" thermodynamic properties, mostly due to the carbon particles that drive heat faster (they melt easier in the heating conduit, upwards -- some like CFPLA really need to be printed fast enough to avoid clogging the nozzle). Now, white should be white. If ever you get some darker bands into your prints, either you are carbonizing it (temp is waay too high!), or your nozzle is dirty and it drags former black filament remains into the print (more likely, but this cannot really last forever!). Try to lower your temperature as much as possible with your white filament?

Comments deleted.
Jun 6, 2017 - Modified Jun 6, 2017

Hi, i tried it with the Webapp. But i don´t get the rough surface like you in the pictures.
I only get a little bit darker filament.

My temperatures are between 200 and 228 °C

Some like it, some prefer a dense, "well printed" result ;)
Actually, if you use lower temperatures (as I did here IIRC), you will start to experience under-extrusions, which will leave gaps in the printed model. A large nozzle makes it also rougher.
All in all it boils down to a mix of the filament properties and the mechanical properties of your driver, but the main parameter is the temperature. Going low is less risky than going too high (carbonized material is no good in the nozzle).

Ah ok, i will experiment a little bit.

Hi. I have used to Cura 2.5 and unfontunatelly and even I putting de wood.py in plugin folder I can`t see it in my Cura. Did u already test it in Cura 2.5...tks in advanced...
BTW: Great job...

Hi there. I just updated the python script from github, the file included here was obsolete.
By the way, I use the older Cura 16.04, could you tell me if it works fine with 2.5 ? :)

It is broken, they changed how the plugins function. I can help rewrite it once I get some free time

Jul 25, 2017 - Modified Jul 25, 2017
MoonCactus - in reply to tracetheory

Thanks for letting me know. Actually I no more feel very comfortable with Ultimaker business strategy (and internal echoes... http://www.tridimake.com/2017/03/ultimaker-patents-and-PR-bullshit.html). Anyhow, I just do not understand why they shot themselves in the foot by ditching/not supporting third party plugins the way they did before. It does not make sense :/

Iv been trying to get this working for the last couple hours on cura 2.5 using the latest file from github with no luck. It does not show up in the plugin list and I do not see any sort of check box for it anywhere in print settings. Looks super though so I might give the site version a try.

unfontunatelly the same problem. =/

Comments deleted.

I can't seem to get the .py file to work with Cura. But I did try the web based tool at https://www.tecrd.com/page/liens/stl_wood and I am impressed with the results.

I have fixed the issue. Cura ignored the file because of missing spaces in the leading comments of the file (!).
You can download it again from github and it should work fine in Cura (tested with 15.04.6 on linux).

I have noticed that the web version introduces weak layers where the print tends to break. Seems to happen when a dark hot layer goes down over a colder lighter layer. I played with the settings but the weak layers come back each time.

Both should give the same results, but I think it probably depends on the material you are printing with.
The only really safe way is to increase the minimum temperature, which is a problem if you want to have also very light bands (as it means barely melting the polymer of the filament... which results in under-extrusions, and possibly poorly merged layers).
Or just cheat: spray or paint a coating or lacquer to the part once it is printed, so it glues it altogether ;)

I tried the standalone version, but always get a syntax error (on windows and mac).

At windows I installed python 2.7. I opened cmd.exe and wrote:
"python wood.py -i 190 -a 230 -g 3.0 -f cube.gcode"
also tried "python wood.py -f cube.gcode"

This gives me:
File "", line1
invalid syntax.

The gcode file is in the same folder as wood.py.
I get the same error at windows and mac.

What am I doing wrong?

Apr 25, 2017 - Modified Apr 25, 2017
MoonCactus - in reply to h4nc

Should work from cmd.exe, but could this be the problem? http://stackoverflow.com/questions/13961140/syntax-error-when-using-command-line-in-python
Either run "python wood.py -f cube.gcode" from a generic shell console (e.g. Win32 on windows), or type only "wood.py -f cube.gcode" if you are already in the Python console? There are also additional suggestions regarding versions and environment variables for these OSes.

A couple of questions: I tried your script but a previous version, it works, almost, the only problem is that for some reason there was no way to pass teh max and min temperatures in a comand line. To solve that I just edited the code with that values.
I see that there is a new version of the script. The beaty is that beinga python script, it can be used in other slicers, like slic3r. In my case I use windows and a face teh same problem: windows doesnt allow you to use the same file in 2 different processes. In perl scripts I solve this useing "$^I = '.bak';" and a second file is generated by the script and problem solved, what would be the line to add in this python script to do that and where shuld be added?
Thanks ina dvance

Oct 5, 2016 - Modified Oct 5, 2016
MoonCactus - in reply to Tinchus2009

Hi there. Ouch, that was more or less my first try on the language even though I am a seasoned programmer on others (and less proficient that you in perl, I did not know the trick -- but I have no such problems, being on linux for the last 15 years...).

I am not sure that I understand why it fails. I am skeptical that there is no way to read-then-write (not append!) a file from within the same python script, especially given that I originally based my script on another plugin from the (now underground!?!) regular Cura plugins. In any case, you may either try to:

  • add a "seek(0)" on the line that follows the "fout= open(filename, "w")" line (should have no impact as I write in "w" mode, not "a" or "a+" as figured on http://stackoverflow.com/questions/14271216/beginner-python-reading-and-writing-to-the-same-file). Please tell me if it fixes your problem, so I can include it in the script.
  • or "fout= open(filename+"_fix.gcode", "w")" for example, since it would change the filename to write to. This would break integration with Cura plugins and probably other slicers, as they expect the same gcode filename on output :/

BTW is the min/max stall an issue with the last script?

http://wiki.ultimaker.com/CuraPlugin:_Wood is not working anymore, the amas the rest of cura plugins, does anybody knows whre to get all those plugins for cura?

Nope, years ago they abandoned this wiki and switched to another one, scrapping the plugins in the same time. Then they kept on saying they will be available again one day since. Frankly, this is disappointing :/ You will have to find them via google, but I am not sure any place has them all!

So glad you posted this - very cool. Thanks!

Sep 28, 2015 - Modified Sep 28, 2015

Works amazingly well within Fedora 22 with FormF coconut filament ;).
Now a question : what's the diff between wood31 & wood32.py ?

hi there! Glad to know. Check the details:

wood31 Fixed obsolete syntax that made Python3 fail (thanks @Mysli)
wood32 is for Python3, should work also on Python2 but untested by me!

You may try the latest one by principle (wood32 then), else just use any that works without trouble for you they are doing basically the exact same job for two flavors of Python.

Comments deleted.

in the web application after uploading my gcode, nothing happens :/

hi...could someone please tell me how to install the plugin in cura? :?

sorry huge delay... I think it boils down to moving the file to a specific folder of Cura. Cura website does not seem to tell chich one (amazing!) but just look with your file manager for one which is already in your default package (e.g. TweakAtZ.py, or by directory name "plugins"), you will just have to copy/paste the file there and start cura again I think

Strange, the website doesn't generate proper g-code for my printer (Flashforge creator x pro) - getting all kinds of errors when I try to print

Did you get it working finally? I am left in the dark without more contextual information (eg. the errors in question!)... Did you check the comments below? It may be due to firmware protections or some other reasons, I cannot help much here.

Sep 19, 2014 - Modified Sep 19, 2014
cassetti - in reply to MoonCactus

Hello! Sadly no, I cannot get it working

I believe this is because my flashforge uses sailfish firmware. I believe I need to compile the gcode for a reprap style printer in slic3r first, then run through he website, and then use a GPX converter to convert the code to use with my sailfish firmware. The error messages pop up when I try to print and RepG checks the code for errors.

I tried to install Cura with the GPX converter to try using the cura plugin to add wood grain later, but I can't get THAT working either. It's to the point where I'm about to give up and simply inject the temp commands into the code by hand

Sep 19, 2014 - Modified Sep 19, 2014
MoonCactus - in reply to cassetti

May be you can send me a (short!) gcode file from your sailfish version and I will have a look at it. I suspect it is ot very hard to fix in the script! jeremie dot francois on gmail

Ah, huh X3G indeed (aka makerbot-only format)... I remember posting a link to someone here posting a solution (which, indeed, required conversion from/to X3G and regular gcode). It worked on a MK so I guess it should work on the Flashforge (a copycat, right?). Sorry, no support for "weird" gcode. Check my post here http://www.tridimake.com/2013/11/a-rant-open-or-closed-you-get-what-you.html

I have a Question in general about Laywood is it possible to print it with a 0.3mm Nozzle ?

I tried it for a very few parts. It worked for me but many people complains about jams with 0.4 mm already (I never experiences jams with mine though). So be prepared for some annoying cleanup. Also, it is not really worth in my opinion, because the filament really welds to itself smoothly (excellet properties that regular filament do not have), so a bigger nozzle is usually enough imo

Yea! Tanks a lot! I have already printed with it now but I used a 0.5mm Nozzle and it works just fine and the results are great!

Glad it worked fine :) This material is really outstanding for art and good-looking prints compared to regular plastics!

Just tried this script on my mac OS10.9. It ran and processed my gcode file but only Z10! the M104 commands were in the gcode but only up to Z10. help? its a Kisslicer gcode file.

If it stopped printing at some height, it could be the firmware protection that halts when it sees an increase of +10 degrees C (then use the proper argument).
Now as you say, if the M104 disappear after Z10 from the gcode I have no clue... may be hopping makes it fail (though it should handle it)! Could you upload the gcode file somehwere so I see better?

What I mean is the temperature changes that the script inserts into the gcode only appear up to Z10. after Z10 there are no more script created temperature changes. I can email you the gcode if you send me your email address if there is a private message ability on here. if not... let me know and maybe dropbox or something

Awfully sorry for the late reply (TV mailing is not great to say the least...).
This is very weird indeed. Yes, feel free to send me your file, using jeremie period francois on gmail, I would like to give it a try myself and know what may be going on! Cheers

MoonCactus, awesome idea :D But i cant get this straight... here you link to your site and your site links back here for the standalone python script :S
And the ones i found got me a syntax error in the "print usage" line.

So could you please simplify this in any way, it would be greatly appreciated :D

The http://wod3.pywod3.py is the latest one, and (probably) the same as my website. Cura holds the latest also as a convenient GUI plugin, My website limits the file size to something barely usable in fact.

Otherwise, in a console, the error message you get about the "usage" probably means that you forgot to specify the arguments or have a bad value. You need to run this script through python in a console... and give it at least one gcode file prefixed with "-f" or "--file".

For example here is how you may run it

python http://wood3.pywood3.py --file myobject.gcode

Check the printed indications when you run the script without any parameters for more options!

Hope it helps!

c:\>python http://wood3.pywood3.py --file lower.gcode

Gives me the following:
File "http://wood3.pywood3.py" line 39
print "usage:"
SyntaxError: invalid syntax

This was executed through cmd.exe windows 7 x64 with python 3.3.3 for windows 7 x64

I have never used python for anything before so im pretty lost here :( it such a shame as i have a lamp shade i have to print for my girlfriend :D

I can't see why it fails... There should be a "tab" caracter before the "print" (Python syntax), but they may get corrupted when you download the file: quite common since windows always thinks that it helps you while it screws the file!
I added "wood3_windows.zip" to make it safer (all as windows like it, and not a text file to be corrupted when downloaded. Tell me!

I just downloaded your zip file and extracted it so that the http://wood3_windows.pywood3_windows.py was in the exact same place and executed it in the exact same way as before and that still gives me the error :S
I checked the file and the tab character is there before the print syntax. i also checked for spaces and there dosent seem to be any...
I just cant see what i am doing wrong... what version of python are you running?

Oh damn you are 100% right. Python 2.X is fine with it but Python 3 complains about the syntax. This file was probably my first python work in 10 years, so I would not remember the syntax and did it with no care, this use of print is obsolete. Here it is fixed (removed the window specific version). Hope it will all be OK now and thanks for not letting it down :)

MoonCactus, You da' man :D
Actually just found out about this by searching google for a bit :) and was actually in the middle of editing the file for 3.x but i guess i wont have to now :D

Wrote another reply earlier, but apparently it didnt get posted :S
But i get this error when running the script on a file
Traceback (most recent call last):
File "http://wood31.pywood31.py", line 194, in <module>
if thisZ != None and maxZ < thisZ:
TypeError: unorderable types: Nonetype() < float()</module>

Looks like I am not proficient enough. Python3 changed a few things and I stumbled on all of them ;)
Uploaded http://Wood32.pyWood32.py and this time I tried it really (but not all the options, so there may be some residual issues in the corners)

That did it :D you're awesome dude :D

Well, that print went very bad :( my whole spool of the laywoo-d3 tangled up midprint and pretty much desintegrated all of it. it was a whole new spool, now i have like 10 meters left thats any good :(
Anyone know why the dont put it on a friggin spool :S

Huh. I once had some brittle laywoo. It was OK to re-heat it in a box to give it some elasticity back, else it just broke all the time in the hobbed bolt (better not pinch it too much). See e.g, http://www.tridimake.com/2012/10/wood-filament-becoming-brittle-after.htmlhttp://www.tridimake.com/2012/...

Very cool thing, but does anybody know how to use this with a makerbot? How can I edit the x3g file? Or an other way, how can I convert a gcode to x3g?
Thanks in advance!

Rather than attempt to modify the exported X3G file, export gcode from MakerWare instead. I can't be sure that this script will work correctly, but it's worth trying.
Once you have exported and modified the gcode, you can use MakerWare to "Print From File" on the gcode.

I do not know and I will even not try. Now my license allows anyone to adapt it to a format that was made to lock you on a much advertized closed-source printer... You'll get more detailed explanations on my blog, I hope you will understand: http://www.tridimake.com/2013/11/a-rant-open-or-closed-you-get-what-you.htmlhttp://www.tridimake.com/2013/...

Can't seem to get the online version to work. How do I incorporate this into Repetier-Host for Mac/Slic3r?

Hi sorry for the late answer. What kind of issue do you have?
Actually you don't have to "incorporate" the script anywhere, but only to run it on the "G-code" file that is produced by your slicers, and before it gets sent to the printer (ie. save the g-code, run the script on it, then load and print the modified g-code file).
Take car the first time in case something goes wrong.

Thanks for responding! I guess, because of my lack of familiarity with Python, I don't know how to "run the script" on my G-code file.

You may have a look at python howto. Eg. on windows, here is a good starting point: http://docs.python.org/2/faq/windowshttp://docs.python.org/2/faq/w...

It is really easy once you open a console (aka terminal), move to the right place and put the files in the proper place. On linux/mac I guess it is even much easier because most of the requirements are met by default:

If you put both the script and the gcode file at the same place, then move to this place in the terminal, just rune this:
python http://wood_standalone.pywood_standalone.py -f yourfile.gcode

And it should work. Then you can play with other options such as min/max temp. Just run again like this to get some information:
python http://wood_standalone.pywood_standalone.py

lol I'm copy/pasting: "Hm sure, but would you send some to me for this free advertising space? ;)"
I'd love to try it indeed, and I have another idea for this filament, but I have so much at home that I don't feel like buying more for now

Wow! Will try it myself and link to your post on website! Thanks a lot!

This is top - thank you. Currently printing an Owl in Laywood scaled to 70% of the original size. This is the second Laywood print I have done - for the first, I had to sit next to the printer for a couple of hours tweaking away at the hot end temperature so this standalone script has enabled me to let it get on with things.

Glad you like it. One thing that makes it better also is the kind of variations applied to the temperature (these are not pure random).
I also fixed something absent from Cura 12.10+: every temperature found in the file was overridden by the plugin, including the last one. So at the end of the print, the nozzle was left hot, which is bad.
This version tries to keep the last temperature (usually something like M104 S0 = cool down).

Make sure to take pictures and post. Any ideas what you'll be printing next?

Oops! Sorry for this, I fixed it on Tue Feb 12 08:35:53 UTC 2013
You can contact me at jeremie francois at gmail

It would be cool if you could have the script show the graph before editing, then if you like it have it edit the file, and if you don't then redo the temperature gradients until you do like it

Good idea. I implemented this in the last version. I also transposed the graph so it easily be viewed in a text editor: now, simply run again the script to update the file. The previous generated temperatures will be overridden, no need to start again with the original file, much easier to tweak then.

So if I don't like the wood temperature graph at the beginning of the gcode, I just run it again on the original gcode file I take it?

Now you just need to re-run the same command line (up arrow + enter in the console), the old temperatures will be discarded and a new plot is generated. Check it in a text editor, it's easier to view now :)

Printed out a Bear with the Wood Filament: http://www.thingiverse.com/thing:49494http://www.thingiverse.com/thi...
Didn't have the python script to run on the gcode before I printed it.

Brown Bear (Ursus arctos) by Makerbot Printed with Wood Filament
by Fused3D

Hm sure, but would you send some to me for this free advertising space? ;)

If you can get a skeinforge plugin made, or standalone plugin made to modify gcode for varying the colors of wood in a print I would happily send you a roll of it.

Yeah! Here you are: I've converted it to a real standalone Python script :)

Well if this turns out and runs on windows good i'll send you some.

Wow, awesome work man. Really, really awesome.

That was originally motivated by my laziness, as I quit did not want to insert M104 commands manually throughout an entire g-code file ;)
I'm glad you like it, but the material itself is the awesome stuff: except for chocolate or clay it is the first one that really looks and feel gorgeous and not like cheap plastic. Still a bit expensive and with its own set of "properties" but one major improvement imho.

SUch a cool idea!

What would it take to run it as a Skeinforge module rather than a Cura module? That way it would be usable by more people. :-)

Yes please, Skeinforge!!