2 #Info: Pause the printer at a certain height
5 #Param: pauseLevel(float:1.0) Pause height (mm)
6 #Param: parkX(float:150) Head park X (mm)
7 #Param: parkY(float:0) Head park Y (mm)
8 #Param: moveZ(float:5) Head move Z (mm)
9 #Param: retractAmount(float:1) Retraction amount (mm)
11 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
13 from Cura.util import profile
15 def getPrintZValue(lineBlock):
17 look for the last z value found just before (or at the same time) G1 code in the given block
20 for line in lineBlock:
21 lastZ = getValue(line, 'Z', lastZ)
22 if line.startswith('G1 ') and (getValue(line, 'X', None) is not None or getValue(line, 'Y', None) is not None):
28 def getValue(line, key, default = None):
29 if not key in line or (';' in line and line.find(key) > line.find(';')):
31 subPart = line[line.find(key) + 1:]
32 m = re.search('^[0-9]+\.?[0-9]*', subPart)
36 return float(m.group(0))
40 with open(filename, "r") as f:
47 #state 0 system is not active until we get to a smaller layer than the last encountered layer (default at 99999) (print one at a time support.)
48 #state 1 system is active and we are looking for our target layer z
49 #state 2 system found the layer it need to write. We will wait for the first G1 or G0 code to write the content just before. state will be set to 0
52 with open(filename, "w") as f:
54 lastLayerIndex = 99999
56 for lIndex in xrange(len(lines)):
58 if line.startswith(';'):
59 if line.startswith(';LAYER:'):
60 currentLayer = int(line[7:].strip())
62 if currentLayer < lastLayerIndex:
65 lastLayerIndex = currentLayer
67 layerZ = getPrintZValue(lines[lIndex:lIndex+20])
68 if layerZ >= pauseLevel:
74 x = getValue(line, 'X', x)
75 y = getValue(line, 'Y', y)
78 g = getValue(line, 'G', None)
79 if g == 1 or g == 0:# We will do the pause just before printing content. We need to pause from the previous XY position. Not the current.
83 f.write(";TYPE:CUSTOM\n")
86 f.write("G1 E-%f F6000\n" % (retractAmount))
89 #Change z before doing the move because the nozzle can hit the glass lock on the UM2
92 f.write("G1 Z15 F300\n")
96 maxZ = profile.getMachineSettingFloat('machine_height') - 10 #For Safety Leave a 10mm space (endstop)
102 f.write("G1 Z%f F300\n" % (newZ))
105 f.write("G1 X%f Y%f F9000\n" % (parkX, parkY))
107 #Disable the E steppers
109 #Wait till the user continues printing
111 #Push the filament back, and retract again, the properly primes the nozzle when changing filament.
112 f.write("G1 E%f F6000\n" % (retractAmount))
113 f.write("G1 E-%f F6000\n" % (retractAmount))
115 #Move the head back. Move Z at the same time to prevent hitting the glass locks on the UM2
117 f.write("G1 X%f Y%f Z%f F9000\n" % (x, y, z))
119 f.write("G1 X%f Y%f F9000\n" % (x, y))
121 f.write("G1 E%f F6000\n" % (retractAmount))
122 f.write("G1 F9000\n")