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))
27 with
open(filename
, "r") as f
:
34 feedrate
= float(profile
.getProfileSetting('print_speed'))
35 wipeTowerP
= profile
.getProfileSetting('wipe_tower') == 'True'
36 currentSectionType
= 'CUSTOM'
39 # todo: move custom gcode to here
40 # detect priming tower and inject reheat there
42 # grab setting from the profile, add a tag at the end of postSwitch,
43 # inject right before the move that sets E0
45 # todo: use 2nd/3rd/etc extruder temp if available (arrays are alright...)
46 printTemperature
= float(profile
.getProfileSetting('print_temperature'))
47 coolTemperature
= printTemperature
- coolTemperatureDifference
48 with
open(filename
, "w") as f
:
50 idx
= lines
.index (';LAYER:0\n')
52 for line
in lines
[0:idx
+1]:
53 if getValue(line
, 'T', None) is not None and getValue(line
, 'M', None) is None:
54 activeExtruder
= getValue(line
, 'T', None)
56 while idx
< len(lines
):
58 if getValue(line
, 'T', None) is not None and getValue(line
, 'M', None) is None:
59 nextExtruder
= getValue(line
, 'T', None)
64 for n
in xrange(startIdx
, idx
):
66 if line
.startswith(';'):
68 g
= getValue(line
, 'G', None)
70 nx
= getValue(line
, 'X', x
)
71 ny
= getValue(line
, 'Y', y
)
72 nz
= getValue(line
, 'Z', z
)
73 feedrate
= getValue(line
, 'F', feedrate
)
74 printTime
+= math
.sqrt((nx
-x
)*(nx
-x
)+(ny
-y
)*(ny
-y
)+(nz
-z
)*(nz
-z
)) / feedrate
* 60
78 heatupTime
= max (printTime
- heatupTimeDelay
, 0.0)
79 heatupBlocked
= True # do not reheat until active extruder is heated
84 f
.write("M104 T%d S%d\n" % (nextExtruder
, coolTemperature
))
85 f
.write("T%d\n" % (activeExtruder
))
88 for n
in xrange(startIdx
, idx
):
90 if line
.startswith(';'):
93 # find where the newly activated extruder is unspooled and block until fully reheated
94 if getValue(line
, 'G', None) is not None and getValue (line
, 'E', 666) == 0.0:
95 # todo: if wipeTowerP, only
96 # wait for a few degrees below
97 # printTemperature and allow
98 # it to finish heating while
101 f
.write ("G91\nG0 Z%.3f\n" % zHop
)
102 f
.write("M109 T%d S%d\n" % (activeExtruder
, printTemperature
))
104 f
.write ("G0 Z%.3f\nG90\n" % -zHop
)
105 heatupBlocked
= False
106 if heatupTime
is not None:
107 g
= getValue(line
, 'G', None)
109 nx
= getValue(line
, 'X', x
)
110 ny
= getValue(line
, 'Y', y
)
111 nz
= getValue(line
, 'Z', z
)
112 feedrate
= getValue(line
, 'F', feedrate
)
113 printTime
+= math
.sqrt((nx
-x
)*(nx
-x
)+(ny
-y
)*(ny
-y
)+(nz
-z
)*(nz
-z
)) / feedrate
* 60
114 if (printTime
> heatupTime
) and (not heatupBlocked
):
115 f
.write("M104 T%d S%d\n" % (nextExtruder
, printTemperature
))
116 f
.write("T%d\n" % (activeExtruder
))
124 activeExtruder
= nextExtruder
126 for n
in xrange(startIdx
, idx
):