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)
9 __copyright__
= "Copyright (C) 2013 David Braam, Copyright (C) 2016 Clinton Ebadi <clinton@unknownlamer.org> - Released under terms of the AGPLv3 License"
12 from Cura
.util
import profile
14 def getValue(line
, key
, default
= None):
15 if not key
in line
or (';' in line
and line
.find(key
) > line
.find(';')):
17 subPart
= line
[line
.find(key
) + 1:]
18 m
= re
.search('^[0-9]+\.?[0-9]*', subPart
)
22 return float(m
.group(0))
26 with
open(filename
, "r") as f
:
33 feedrate
= float(profile
.getProfileSetting('print_speed'))
34 currentSectionType
= 'CUSTOM'
37 # todo: move custom gcode to here
38 # detect priming tower and inject reheat there
40 # grab setting from the profile, add a tag at the end of postSwitch,
41 # inject right before the move that sets E0
43 # todo: use 2nd/3rd/etc extruder temp if available (arrays are alright...)
44 printTemperature
= float(profile
.getProfileSetting('print_temperature'))
45 coolTemperature
= printTemperature
- coolTemperatureDifference
46 with
open(filename
, "w") as f
:
48 idx
= lines
.index (';LAYER:0\n')
50 for line
in lines
[0:idx
+1]:
51 if getValue(line
, 'T', None) is not None and getValue(line
, 'M', None) is None:
52 activeExtruder
= getValue(line
, 'T', None)
54 while idx
< len(lines
):
57 if getValue(line
, 'T', None) is not None and getValue(line
, 'M', None) is None:
58 nextExtruder
= getValue(line
, 'T', None)
63 for n
in xrange(startIdx
, idx
):
65 if line
.startswith(';'):
67 g
= getValue(line
, 'G', None)
69 nx
= getValue(line
, 'X', x
)
70 ny
= getValue(line
, 'Y', y
)
71 nz
= getValue(line
, 'Z', z
)
72 feedrate
= getValue(line
, 'F', feedrate
)
73 printTime
+= math
.sqrt((nx
-x
)*(nx
-x
)+(ny
-y
)*(ny
-y
)+(nz
-z
)*(nz
-z
)) / feedrate
* 60
77 heatupTime
= printTime
- heatupTimeDelay
82 f
.write("M104 T%d S%d\n" % (nextExtruder
, coolTemperature
))
83 f
.write("T%d\n" % (activeExtruder
))
85 heatupTime
= printTime
/ 2
86 # clinton: custom gcode sets cooltemp, need to counteract that for short layers
87 #f.write("M104 T%d S%d\n" % (nextExtruder, printTemperature - coolTemperatureDifference/2))
88 #f.write("T%d\n" % (activeExtruder))
90 for n
in xrange(startIdx
, idx
):
92 if line
.startswith(';'):
94 if (line
== ';HEATER_BLOCKED\n'):
96 elif (line
== ';HEATER_UNBLOCKED\n'):
99 if heatupTime
is not None:
100 g
= getValue(line
, 'G', None)
102 nx
= getValue(line
, 'X', x
)
103 ny
= getValue(line
, 'Y', y
)
104 nz
= getValue(line
, 'Z', z
)
105 feedrate
= getValue(line
, 'F', feedrate
)
106 printTime
+= math
.sqrt((nx
-x
)*(nx
-x
)+(ny
-y
)*(ny
-y
)+(nz
-z
)*(nz
-z
)) / feedrate
* 60
107 if (printTime
> heatupTime
) and (not heatupBlocked
):
108 f
.write("M104 T%d S%d\n" % (nextExtruder
, printTemperature
))
109 f
.write("T%d\n" % (activeExtruder
))
116 heatupBlocked
= False
118 activeExtruder
= nextExtruder
120 for n
in xrange(startIdx
, idx
):