chiark / gitweb /
Add proper copyright statements.
[cura.git] / Cura / plugins / pauseAtZ.py
1 #Name: Pause at height
2 #Info: Pause the printer at a certain height
3 #Depend: GCode
4 #Type: postprocess
5 #Param: pauseLevel(float:5.0) Pause height (mm)
6 #Param: parkX(float:190) Head park X (mm)
7 #Param: parkY(float:190) Head park Y (mm)
8 #Param: retractAmount(float:5) Retraction amount (mm)
9
10 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
11 import re
12
13 def getValue(line, key, default = None):
14         if not key in line or (';' in line and line.find(key) > line.find(';')):
15                 return default
16         subPart = line[line.find(key) + 1:]
17         m = re.search('^[0-9]+\.?[0-9]*', subPart)
18         if m is None:
19                 return default
20         try:
21                 return float(m.group(0))
22         except:
23                 return default
24
25 with open(filename, "r") as f:
26         lines = f.readlines()
27
28 z = 0
29 x = 0
30 y = 0
31 pauseState = 0
32 with open(filename, "w") as f:
33         for line in lines:
34                 if line.startswith(';'):
35                         if line.startswith(';TYPE:'):
36                                 currentSectionType = line[6:].strip()
37                         f.write(line)
38                         continue
39                 if getValue(line, 'G', None) == 1:
40                         newZ = getValue(line, 'Z', z)
41                         x = getValue(line, 'X', x)
42                         y = getValue(line, 'Y', y)
43                         if newZ != z and currentSectionType != 'CUSTOM':
44                                 z = newZ
45                                 if z < pauseLevel and pauseState == 0:
46                                         pauseState = 1
47                                 if z >= pauseLevel and pauseState == 1:
48                                         pauseState = 2
49                                         f.write(";TYPE:CUSTOM\n")
50                                         #Retract
51                                         f.write("M83\n")
52                                         f.write("G1 E-%f F6000\n" % (retractAmount))
53                                         #Move the head away
54                                         f.write("G1 X%f Y%f F9000\n" % (parkX, parkY))
55                                         if z < 15:
56                                                 f.write("G1 Z15 F300\n")
57                                         #Wait till the user continues printing
58                                         f.write("M0\n")
59                                         #Push the filament back, and retract again, the properly primes the nozzle when changing filament.
60                                         f.write("G1 E%f F6000\n" % (retractAmount))
61                                         f.write("G1 E-%f F6000\n" % (retractAmount))
62                                         #Move the head back
63                                         f.write("G1 X%f Y%f F9000\n" % (x, y))
64                                         f.write("G1 E%f F6000\n" % (retractAmount))
65                                         f.write("G1 F9000\n")
66                                         f.write("M82\n")
67                 f.write(line)