Welcome! Log In Create A New Profile

Advanced

Wood Plugin for Slic3r?

Posted by labmat 
Wood Plugin for Slic3r?
January 22, 2013 10:53PM
I've been doing a lot of Laywoo-D3 printing lately and have been getting great results with Slic3r (I wish I would have ditched Skeinforge sooner). I haver however been wanting to vary the temperature throughout the print like demonstrated on Jeremie Francois blog , really neat stuff. Does anyone know if his plugin is compatible with Slic3r?


________________________________

Matthew LaBerge
[reprap.iceboxrobotics.com]
Re: Wood Plugin for Slic3r?
January 23, 2013 02:51AM
Quote
Jeremie Francois
So I developed a Cura & Skeinforge plugin that inserts the appropriate M104 at each layer...

Skeinforge (and Cura) have plugins that carry out functions such as Carve, Multiply, Dimension, ...
This Laywoo-D3 plugin is one such plugin.

NO, it will NOT work with Slic3r which is an EXE and not a python program!


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Re: Wood Plugin for Slic3r?
January 23, 2013 07:31AM
Darn, I guess I can only hope that this functionality makes it into Slic3r on its own. Kinda wish he would have made the plugin as a separate script you could run on any g-code file.


________________________________

Matthew LaBerge
[reprap.iceboxrobotics.com]
Re: Wood Plugin for Slic3r?
January 23, 2013 08:09AM
I don't think it is very difficult to write a script which parse the Gcode and add the command M104 SXXX function of the height print

could be done in perl I think
Re: Wood Plugin for Slic3r?
January 23, 2013 08:26AM
I could do it in AWK (perl I don't like as well, too cryptic).


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Re: Wood Plugin for Slic3r?
January 23, 2013 04:22PM
That woud be pretty awesome, how difficult is it to write this script?
Re: Wood Plugin for Slic3r?
January 23, 2013 09:54PM
There is a varient written in python as a post-processor for Cura: [wiki.ultimaker.com]

(from this page: [wiki.ultimaker.com] )

Maybe thios could be called with the postprocessing scrip option?

-Rob A>
Re: Wood Plugin for Slic3r?
January 24, 2013 02:06AM
the trik would be to write a stand alone utility able to work with any Gcode to independant of the slicer
Re: Wood Plugin for Slic3r?
January 24, 2013 02:26AM
Yes, the Wood plugin is written as a post processing step and as such should be able to be used with any gcode file!

#Name: Wood
#Info: Vary the print temperature troughout the print to create wood rings with the LayWood printing material
#Depend: GCode
#Type: postprocess
#Param: minTemp(float:180) Min print temperature (c)
#Param: maxTemp(float:230) Max print temperature (c)
#Param: grainSize(float:3.0) Average Grain Size (mm)

import re
import random
import math

__author__ = 'Jeremie Francois ([email protected])'
__date__ = '$Date: 2012/10/26 $'
__license__ = 'GNU Affero General Public License [www.gnu.org]'

def getValue(line, key, default = None):
	if not key in line or (';' in line and line.find(key) > line.find(';')):
		return default
	subPart = line[line.find(key) + 1:]
	m = re.search('^[0-9]+\.?[0-9]*', subPart)
	if m == None:
		return default
	try:
		return float(m.group(0))
	except:
		return default

class Perlin:
	# Perlin noise: [mrl.nyu.edu]

	def __init__(self, tiledim=256):
		self.tiledim= tiledim
		self.perm = [None]*2*tiledim

		permutation = []
		for value in xrange(tiledim): permutation.append(value)
		random.shuffle(permutation)

		for i in xrange(tiledim):
			self.perm = permutation
			self.perm[tiledim+i] = self.perm

	def fade(self, t):
		return t * t * t * (t * (t * 6 - 15) + 10)

	def lerp(self, t, a, b):
		return a + t * (b - a)

	def grad(self, hash, x, y, z):
		#CONVERT LO 4 BITS OF HASH CODE INTO 12 GRADIENT DIRECTIONS.
		h = hash & 15
		if h < 8: u = x
		else:     u = y
		if h < 4: v = y
		else:
			if h == 12 or h == 14: v = x
			else:                  v = z
		if h&1 == 0: first = u
		else:        first = -u
		if h&2 == 0: second = v
		else:        second = -v
		return first + second

	def noise(self, x,y,z):
		#FIND UNIT CUBE THAT CONTAINS POINT.
		X = int(x)&(self.tiledim-1)
		Y = int(y)&(self.tiledim-1)
		Z = int(z)&(self.tiledim-1)
		#FIND RELATIVE X,Y,Z OF POINT IN CUBE.
		x -= int(x)
		y -= int(y)
		z -= int(z)
		#COMPUTE FADE CURVES FOR EACH OF X,Y,Z.
		u = self.fade(x)
		v = self.fade(y)
		w = self.fade(z)
		#HASH COORDINATES OF THE 8 CUBE CORNERS
		A = self.perm[X  ]+Y; AA = self.perm[A]+Z; AB = self.perm[A+1]+Z
		B = self.perm[X+1]+Y; BA = self.perm+Z; BB = self.perm[B+1]+Z
		#AND ADD BLENDED RESULTS FROM 8 CORNERS OF CUBE
		return self.lerp(w,self.lerp(v,
				self.lerp(u,self.grad(self.perm[AA  ],x  ,y  ,z  ), self.grad(self.perm[BA  ],x-1,y  ,z  )),
				self.lerp(u,self.grad(self.perm[AB  ],x  ,y-1,z  ), self.grad(self.perm[BB  ],x-1,y-1,z  ))),
			self.lerp(v,
				self.lerp(u,self.grad(self.perm[AA+1],x  ,y  ,z-1), self.grad(self.perm[BA+1],x-1,y  ,z-1)),
				self.lerp(u,self.grad(self.perm[AB+1],x  ,y-1,z-1), self.grad(self.perm[BB+1],x-1,y-1,z-1))))

	def fractal(self, octaves, persistence, x,y,z, frequency=1):
		value = 0.0
		amplitude = 1.0
		totalAmplitude= 0.0
		for octave in xrange(octaves):
			n= self.noise(x*frequency,y*frequency,z*frequency)
			value += amplitude * n
			totalAmplitude += amplitude
			amplitude *= persistence
			frequency *= 2
		return value / totalAmplitude


with open(filename, "r") as f:
	lines = f.readlines()

#Find the total height of the object
maxZ = 0
z = 0
for line in lines:
	if getValue(line, 'G', None) == 1:
		z = getValue(line, 'Z', z)
		if maxZ < z:
			maxZ = z

"First pass generates the noise curve, we'll normalize it afterwards because the user expects to reach the min & max temperatures"
perlin = Perlin()
noises = []
banding = 5
octaves = 3
persistence = 0.5
z = 0
for line in lines:
	if getValue(line, 'G', None) == 1:
		newZ = getValue(line, 'Z', z)
		if newZ != z:
			z = newZ
			noise= banding * perlin.fractal(octaves, persistence, 0,0,z/(grainSize*2));
			noise = (noise - math.floor(noise))
			noises.append(noise)
temps = []
maxNoises = max(noises)
minNoises = min(noises)
for n in noises:
	nn = ( n - minNoises ) / ( maxNoises - minNoises )
	temps.append(minTemp + (maxTemp - minTemp) * nn)

#Save the file with M104 temperature settings per layer
z = 0
idx = 0
with open(filename, "w") as f:
	f.write(";Wood temperature graph:\n")
	for n in xrange(15, 0, -1):
		str = ";%3i | " % (minTemp + (maxTemp - minTemp) * n / 15)
		for t in temps:
			if (t - minTemp) / (maxTemp - minTemp) * 15 >= (n - 0.5):
				str += "#"
			else:
				str += " "
		f.write(str + "\n")
	for line in lines:
		if getValue(line, 'G', None) == 1:
			newZ = getValue(line, 'Z', z)
			if newZ != z:
				z = newZ
				
				f.write("M104 S%i\n" % (temps[idx]))
				idx += 1
		f.write(line)

The code reads in the entire gcode file, calclulates the perlin noise function and then outputs the gcode file inserting an
M104 S[temp] command for every change in Z layer (probably won't work if hop is enabled). I will play with this some and let you know.


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Re: Wood Plugin for Slic3r?
January 24, 2013 02:42AM
for use with hop enable may be it is possible to apply the change at the first level occurence

so the temp change will be applyed at the high + hop amount

not a big deal because there is no need for a real precision it is just a cosmetic plugin

thank you

by the way hox to use the script for non programming aware user ?
Re: Wood Plugin for Slic3r?
January 24, 2013 02:48AM
THAT is what I don't know yet!

I suspect something like:
python -v filename=myfile.gcode wood.py

or something similar.

Since it is a post processing plugin for Cura it should be possible to look in the Cura source code to see how it is invoked.


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Re: Wood Plugin for Slic3r?
January 24, 2013 02:49AM
may be only need to change
if newZ != z:
z = newZ

with
if newZ > z:
z = newZ


like that it will write the m104 s(temp) at each time the z lift to a new upper value
Re: Wood Plugin for Slic3r?
January 24, 2013 03:19AM
No, that wouldn't work - the first hop would change the temperature even though the current layer should be at a different temperature. Since I don't have hop active it would work for me as is.


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Re: Wood Plugin for Slic3r?
January 24, 2013 04:34AM
yes but as hop is barely over 0.5 or 1 mm, it means only the temp change will be the hop high sooner not a big deal i think as it is purely cometic that's not a dimensional pb ( and even if the temp change in the middle of a layer, what's wrong with that ?
Re: Wood Plugin for Slic3r?
January 24, 2013 04:38AM
True, it would probably work OK.


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Re: Wood Plugin for Slic3r?
January 24, 2013 11:23AM
Try the attached file Wood.py

If python is installed properly it can be invoked as follows:
Wood.py -h -g <grainSize> -i <input> -o <output> -n <minTemp> -x <maxTemp>

where;
  -h  Show the usage info
  -g  Sets the grainSize (default 3mm)
  -i  Sets the input gcode filename
  -o  Sets the output gcode filename
  -n  Sets the minimum temperature (default 190°C)
  -x  Sets the maximum temperature (default 240°C)

For example if I have "owl.gcode" then I might use:
Wood.py -i owl.gcode -o owlWood.gcode

I did a quick test and it appears to work well.
Let me know if you have any problems.


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Re: Wood Plugin for Slic3r?
January 24, 2013 11:46AM
BTW you should probably do the change that you thought of:

Quote
jf pion
may be only need to REPLACE:

if newZ != z:
    z = newZ

WITH:

if newZ > z:
    z = newZ

since you apparently have HOP active.


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Re: Wood Plugin for Slic3r?
January 24, 2013 03:12PM
I will try

which version of python ? 2 or 3 ?

thanks
Re: Wood Plugin for Slic3r?
January 24, 2013 03:41PM
I have Python 2.6.6 Installed.


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Re: Wood Plugin for Slic3r?
January 24, 2013 03:54PM
can't make the thing work

win 7

python 2.7.3

open the command window

cd i: (that's where the woody.py and stl files are)
I write :
I:\>Wood.py -h -i coupler_slic3rl.gcode -o coupler_slic3rWood.gcode -n 190 -x 24
0

and I get :

Wood.py -h -g -i -o -n -x

I:\>

and no gcode generated

I must do something wrong, i'm not used to use python on win 7 (not at all in fact)

thank you
Re: Wood Plugin for Slic3r?
January 24, 2013 04:08PM
Of course, because you specified the help flag "-h".
This means output the usage and exit.

Use the following command line:
Wood.py -i coupler_slic3rl.gcode -o coupler_slic3rWood.gcode -n 190 -x 240


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Re: Wood Plugin for Slic3r?
January 24, 2013 04:41PM
ok i haven't got the meaning of -h

thank you
Re: Wood Plugin for Slic3r?
January 24, 2013 08:34PM
I just get a permission denied error when I try to run it on my MacBook, I must be doing something wrong.
Re: Wood Plugin for Slic3r?
January 24, 2013 11:35PM
Not sure what changed, all I did was try to run the script one last time before giving up for the night and I go the following errors.

Matthews-MacBook-Pro-3:~ matthewlaberge$ /Volumes/BigDisk/Downloads/Wood.py -i Owl.gcode -o OwlWood.gcode
/Volumes/BigDisk/Downloads/Wood.py: line 9: import: command not found
/Volumes/BigDisk/Downloads/Wood.py: line 10: import: command not found
/Volumes/BigDisk/Downloads/Wood.py: line 11: import: command not found
/Volumes/BigDisk/Downloads/Wood.py: line 12: import: command not found
/Volumes/BigDisk/Downloads/Wood.py: line 13: import: command not found
/Volumes/BigDisk/Downloads/Wood.py: line 15: __author__: command not found
/Volumes/BigDisk/Downloads/Wood.py: line 16: __date__: command not found
/Volumes/BigDisk/Downloads/Wood.py: line 17: __license__: command not found
/Volumes/BigDisk/Downloads/Wood.py: line 19: syntax error near unexpected token `('
/Volumes/BigDisk/Downloads/Wood.py: line 19: `def getValue(line, key, default = None):'

Am I missing something, I installed Python 2.7 for the first time this morning.
Re: Wood Plugin for Slic3r?
January 25, 2013 12:25AM
I kinda fixed my own problem, I searched the web and found that those of us running OSX or Linux should add the following line to the beginning of the Wood.py script

#!/usr/bin/python

Once I did this it took me a little more time to figure out that I had to specifiy the exact file path for the input and output gcode file, I had just assumed that that the script would know to find the input and output it in the same directory as the script. My terminal command looked like the following.

Matthews-MacBook-Pro-3:~ matthewlaberge$ /Volumes/BigDisk/Downloads/Wood.py -i /Volumes/BigDisk/Downloads/Owl.gcode -o /Volumes/BigDisk/Downloads/OwlWood.gcode -n 180 -x 220

I now have the following prepended to a g-code file as well as a boat load of M104 SXX commands throught the file. I will print a test part tomorrow morning.

;Wood temperature graph:
;240 |
;236 |
;233 |
;230 |
;226 | #
;223 | #
;220 | #
;216 | #
;213 | #
;210 | #
;206 | #
;203 | #
;200 | #
;196 | #
;193 | #

Thanks you so much for uploading this script Bob!

Edited 1 time(s). Last edit at 01/25/2013 12:27AM by labmat.
Re: Wood Plugin for Slic3r?
January 25, 2013 03:19AM
smileys with beer


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Re: Wood Plugin for Slic3r?
January 25, 2013 03:21AM
Your graph looks a little funny though.
For my test part it looks as follows:
;Wood temperature graph:
;240 |                                         #                           #     
;236 | # #     # #              #              #     ##             #      #     
;233 | # #   ### #      #    #  #  #       #   #  #  ###            #  #   #     
;230 | # #   ### #    # #    #  #  #       #   #  #  ###           ##  #   # ##  
;226 | # #   #####   ## #    #  #  ##      #   #  #  ###        #  ##  #   # ##  
;223 | # #   #####  ### #  # #  #  ##      #   #  #  ###      # #  ##  ### # ### 
;220 | # # # #####  ### #  # #  #  ##      #   #  #  ###      # #  ##  ### ##### 
;216 | # # # ###### ### #  # #  #  ##      #   #  ## ###      # #  ##  ### ##### 
;213 | # # # ###### ### ## # #  #  ##      # # #  ## ###     ## ## ##  ### ##### 
;210 | # ### ###### ### ## # #  #  ##    # # # #  ## ###     ## ## ### ### ######
;206 | # ### ###### ### ## # #  #  ##   ## # # #  ## ###     ## ## ### ### ######
;203 | # ########## ### ## # #  #  ### ### # # ## ## ###    ### ## ### ### ######
;200 | # ########## ### ## # #  #  ####### # # ## ## ###    ### ## ####### ######
;196 | # ############## ## ###  ## ########### ## ## ### #  ### ## ##############
;193 | # ################# #### ## ########### ## ## ### ######### ##############


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Re: Wood Plugin for Slic3r?
January 25, 2013 03:54AM
Quote
labmat
Once I did this it took me a little more time to figure out that I had to specifiy the exact file path for the input and output gcode file, I had just assumed that that the script would know to find the input and output it in the same directory as the script. My terminal command looked like the following.

If you changed your current directory to "/Volumes/BigDisk/Downloads/" then you could use:
Matthews-MacBook-Pro-3:~ matthewlaberge$ Wood.py -i Owl.gcode -o OwlWood.gcode -n 180 -x 220


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Re: Wood Plugin for Slic3r?
January 27, 2013 10:17AM
After a few failures, I have successfully completed a print with visible rings. The owl turned out pretty good, only one dark booger on tip of one of his wings. I will be tweaking the settings some as I would like to see even more color variation.




Thanks for posting the script Bob!
Re: Wood Plugin for Slic3r?
January 29, 2013 11:49AM
You may probably increase a bit your temperatures to get darker bands imho, and may be a bit the frequency also if you want narrower bands (you may have seen my version (http://betterprinter.blogspot.fr/2012/10/shades-of-brown-with-wood-filament-via.html)

As Bob found out, it should be pretty easy to port and inclulde it in slic3r btw (and I could even help if needed), but pease let me know! I am the author of the script (Daid incuded my initial skeinforge plugin into latest Cura) smiling smiley
Sorry, only registered users may post in this forum.

Click here to login