2 #Info: Lower the temperature for the nozzle that is not printing
5 #Param: coolTemperatureDifference(float:50.0) Drop idle nozzle temperature (C)
6 #Param: heatupTimeDelay(float:20.0) Heatup nozzle before use (sec)
7 #Param: zHop(float:0.0) Raise Z when reheating active extruder (mm)
10 __copyright__
= "Copyright (C) 2013 David Braam, Copyright (C) 2016 Clinton Ebadi <clinton@unknownlamer.org> - Released under terms of the AGPLv3 License"
13 from Cura
.util
import profile
15 def getValue(line
, key
, default
= None):
16 if not key
in line
or (';' in line
and line
.find(key
) > line
.find(';')):
18 subPart
= line
[line
.find(key
) + 1:]
19 m
= re
.search('^[0-9]+\.?[0-9]*', subPart
)
23 return float(m
.group(0))
31 G0 X-{d} Y-{d} F{rate}
32 G0 X-{d} Y-{d} F{rate}
35 """.format (d
=3, rate
=float(profile
.getProfileSetting('travel_speed')) * 60))
40 if fanOnCommand
is not None:
44 if fanOnCommand
is not None:
45 # ensure fan actually kicks back on
46 f
.write ("M106 S255\n")
47 f
.write (fanOnCommand
)
49 with
open(filename
, "r") as f
:
56 feedrate
= float(profile
.getProfileSetting('print_speed'))
57 wipeTowerP
= profile
.getProfileSetting('wipe_tower') == 'True'
58 currentSectionType
= 'CUSTOM'
61 # todo: use 2nd/3rd/etc extruder temp if available (arrays are alright...)
62 printTemperature
= float(profile
.getProfileSetting('print_temperature'))
63 coolTemperature
= printTemperature
- coolTemperatureDifference
65 with
open(filename
, "w") as f
:
67 idx
= lines
.index (';LAYER:0\n')
69 for line
in lines
[0:idx
]:
70 if getValue(line
, 'T', None) is not None and getValue(line
, 'M', None) is None:
71 activeExtruder
= getValue(line
, 'T', None)
73 while idx
< len(lines
):
75 if getValue(line
, 'T', None) is not None and getValue(line
, 'M', None) is None:
76 nextExtruder
= getValue(line
, 'T', None)
81 for n
in xrange(startIdx
, idx
):
83 if line
.startswith(';'):
85 g
= getValue(line
, 'G', None)
87 nx
= getValue(line
, 'X', x
)
88 ny
= getValue(line
, 'Y', y
)
89 nz
= getValue(line
, 'Z', z
)
90 feedrate
= getValue(line
, 'F', feedrate
)
91 printTime
+= math
.sqrt((nx
-x
)*(nx
-x
)+(ny
-y
)*(ny
-y
)+(nz
-z
)*(nz
-z
)) / feedrate
* 60
96 heatupTime
= printTime
- heatupTimeDelay
98 heatupTime
= printTime
/ 2.0 #None
99 heatupBlocked
= not firstLayer
# do not reheat until active extruder is heated
104 f
.write("M104 T%d S%d\n" % (nextExtruder
, coolTemperature
))
105 f
.write("T%d\n" % (activeExtruder
))
108 for n
in xrange(startIdx
, idx
):
110 if line
.startswith(';'):
113 if getValue(line
, 'M', 666) == 107:
117 if getValue(line
, 'M', 666) == 106:
121 # find where the newly activated extruder is unspooled and block until fully reheated
122 if (getValue(line
, 'G', 666) == 0 or getValue(line
, 'G', 666) == 1) and getValue (line
, 'E', 666) == 0.0 and (heatupBlocked
or firstLayer
):
123 # todo: if wipeTowerP, only
124 # wait for a few degrees below
125 # printTemperature and allow
126 # it to finish heating while
129 f
.write ("G91\nG0 Z%.3f\nG90\n" % zHop
)
132 f
.write("M109 T%d S%d\n" % (activeExtruder
, printTemperature
))
137 f
.write ("G91\nG0 Z%.3f\nG90\n" % -zHop
)
139 heatupBlocked
= False
140 if heatupTime
is not None:
141 g
= getValue(line
, 'G', None)
143 nx
= getValue(line
, 'X', x
)
144 ny
= getValue(line
, 'Y', y
)
145 nz
= getValue(line
, 'Z', z
)
146 feedrate
= getValue(line
, 'F', feedrate
)
147 printTime
+= math
.sqrt((nx
-x
)*(nx
-x
)+(ny
-y
)*(ny
-y
)+(nz
-z
)*(nz
-z
)) / feedrate
* 60
148 if (printTime
> heatupTime
) and (not heatupBlocked
):
149 f
.write("M104 T%d S%d\n" % (nextExtruder
, printTemperature
))
150 f
.write("T%d\n" % (activeExtruder
))
158 activeExtruder
= nextExtruder
161 for n
in xrange(startIdx
, idx
):