chiark / gitweb /
Merge pull request #601 from CapnBry/reloadscene
[cura.git] / 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 currentSectionType = 'STARTOFFILE'
33 with open(filename, "w") as f:
34         for line in lines:
35                 if line.startswith(';'):
36                         if line.startswith(';TYPE:'):
37                                 currentSectionType = line[6:].strip()
38                         f.write(line)
39                         continue
40                 if getValue(line, 'G', None) == 1 or getValue(line, 'G', None) == 0:
41                         newZ = getValue(line, 'Z', z)
42                         x = getValue(line, 'X', x)
43                         y = getValue(line, 'Y', y)
44                         if newZ != z and currentSectionType != 'CUSTOM':
45                                 z = newZ
46                                 if z < pauseLevel and pauseState == 0:
47                                         pauseState = 1
48                                 if z >= pauseLevel and pauseState == 1:
49                                         pauseState = 2
50                                         f.write(";TYPE:CUSTOM\n")
51                                         #Retract
52                                         f.write("M83\n")
53                                         f.write("G1 E-%f F6000\n" % (retractAmount))
54                                         #Move the head away
55                                         f.write("G1 X%f Y%f F9000\n" % (parkX, parkY))
56                                         if z < 15:
57                                                 f.write("G1 Z15 F300\n")
58                                         #Wait till the user continues printing
59                                         f.write("M0\n")
60                                         #Push the filament back, and retract again, the properly primes the nozzle when changing filament.
61                                         f.write("G1 E%f F6000\n" % (retractAmount))
62                                         f.write("G1 E-%f F6000\n" % (retractAmount))
63                                         #Move the head back
64                                         if z < 15:
65                                                 f.write("G1 Z%f F300\n" % (z+1))
66                                         f.write("G1 X%f Y%f F9000\n" % (x, y))
67                                         f.write("G1 E%f F6000\n" % (retractAmount))
68                                         f.write("G1 F9000\n")
69                                         f.write("M82\n")
70                 f.write(line)