chiark / gitweb /
Merge branch 'SteamEngine' of github.com:daid/Cura into SteamEngine
[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: moveZ(float:0) Head move Z (mm)
9 #Param: retractAmount(float:5) Retraction amount (mm)
10
11 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
12 import re
13 from Cura.util import profile
14
15 def getValue(line, key, default = None):
16         if not key in line or (';' in line and line.find(key) > line.find(';')):
17                 return default
18         subPart = line[line.find(key) + 1:]
19         m = re.search('^[0-9]+\.?[0-9]*', subPart)
20         if m is None:
21                 return default
22         try:
23                 return float(m.group(0))
24         except:
25                 return default
26
27 with open(filename, "r") as f:
28         lines = f.readlines()
29
30 z = 0.
31 x = 0.
32 y = 0.
33 pauseState = 0
34 currentSectionType = 'STARTOFFILE'
35 with open(filename, "w") as f:
36         for line in lines:
37                 if line.startswith(';'):
38                         if line.startswith(';TYPE:'):
39                                 currentSectionType = line[6:].strip()
40                         f.write(line)
41                         continue
42                 if getValue(line, 'G', None) == 1 or getValue(line, 'G', None) == 0:
43                         newZ = getValue(line, 'Z', z)
44                         x = getValue(line, 'X', x)
45                         y = getValue(line, 'Y', y)
46                         if newZ != z and currentSectionType != 'CUSTOM':
47                                 z = newZ
48                                 if z < pauseLevel and (pauseState == 0 or pauseState == 2): #pauseState going from 2 to 1 mean we can support print one at a time mode.
49                                         pauseState = 1
50                                 if z >= pauseLevel and pauseState == 1:
51                                         pauseState = 2
52                                         f.write(";TYPE:CUSTOM\n")
53                                         #Retract
54                                         f.write("M83\n")
55                                         f.write("G1 E-%f F6000\n" % (retractAmount))
56
57                                         zChanged = False
58                                         #Change z before doing the move because the nozzle can hit the glass lock on the UM2
59                                         if z + moveZ < 15:
60                                                 zChanged = True
61                                                 f.write("G1 Z15 F300\n")
62
63                                         elif moveZ > 0:
64                                                 newZ = z + moveZ
65                                                 maxZ = profile.getMachineSettingFloat('machine_height') - 10 #For Safety Leave a 10mm space (endstop)
66                                                 if maxZ < newZ:
67                                                         newZ = maxZ
68
69                                                 if newZ > z:
70                                                         zChanged = True
71                                                         f.write("G1 Z%f F300\n" % (newZ))
72
73                                         #Move the head away
74                                         f.write("G1 X%f Y%f F9000\n" % (parkX, parkY))
75
76                                         #Disable the E steppers
77                                         f.write("M84 E0\n")
78                                         #Wait till the user continues printing
79                                         f.write("M0\n")
80                                         #Push the filament back, and retract again, the properly primes the nozzle when changing filament.
81                                         f.write("G1 E%f F6000\n" % (retractAmount))
82                                         f.write("G1 E-%f F6000\n" % (retractAmount))
83
84                                         #Move the head back. Move Z at the same time to prevent hitting the glass locks on the UM2
85                                         if zChanged :
86                                                 f.write("G1 X%f Y%f Z%f F9000\n" % (x, y, z+1))
87                                         else:
88                                                 f.write("G1 X%f Y%f F9000\n" % (x, y))
89
90                                         f.write("G1 E%f F6000\n" % (retractAmount))
91                                         f.write("G1 F9000\n")
92                                         f.write("M82\n")
93                 f.write(line)