chiark / gitweb /
Add pauze at height plugin.
[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 import re
11
12 def getValue(line, key, default = None):
13         if not key in line or (';' in line and line.find(key) > line.find(';')):
14                 return default
15         subPart = line[line.find(key) + 1:]
16         m = re.search('^[0-9]+\.?[0-9]*', subPart)
17         if m == None:
18                 return default
19         try:
20                 return float(m.group(0))
21         except:
22                 return default
23
24 with open(filename, "r") as f:
25         lines = f.readlines()
26
27 z = 0
28 x = 0
29 y = 0
30 pauseState = 0
31 with open(filename, "w") as f:
32         for line in lines:
33                 if getValue(line, 'G', None) == 1:
34                         newZ = getValue(line, 'Z', z)
35                         x = getValue(line, 'X', x)
36                         y = getValue(line, 'Y', y)
37                         if newZ != z:
38                                 z = newZ
39                                 if z < pauseLevel and pauseState == 0:
40                                         pauseState = 1
41                                 if z >= pauseLevel and pauseState == 1:
42                                         pauseState = 2
43                                         #Retract
44                                         f.write("M83\n")
45                                         f.write("G1 E-%f F6000\n" % (retractAmount))
46                                         #Move the head away
47                                         f.write("G1 X%f Y%f F9000\n" % (parkX, parkY))
48                                         #Wait till the user continues printing
49                                         f.write("M0\n")
50                                         #Move the head back
51                                         f.write("G1 X%f Y%f F9000\n" % (x, y))
52                                         f.write("G1 E%f F6000\n" % (retractAmount))
53                                         f.write("G1 F9000\n")
54                                         f.write("M82\n")
55                 f.write(line)