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: parkMinZ(float:15) Minimum head park Z (mm, abs)
10 #Param: retractAmount(float:1) Retraction amount (mm)
11 #Param: homeX(bool:true) Re-home X on restart
12 #Param: homeY(bool:false) Re-home Y on restart
14 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
16 from Cura.util import profile
18 def getPrintZValue(lineBlock):
20 look for the last z value found just before (or at the same time) G1 code in the given block
23 for line in lineBlock:
24 lastZ = getValue(line, 'Z', lastZ)
25 if line.startswith('G1 ') and (getValue(line, 'X', None) is not None or getValue(line, 'Y', None) is not None):
31 def getValue(line, key, default = None):
32 if not key in line or (';' in line and line.find(key) > line.find(';')):
34 subPart = line[line.find(key) + 1:]
35 m = re.search('^[0-9]+\.?[0-9]*', subPart)
39 return float(m.group(0))
43 with open(filename, "r") as f:
50 #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.)
51 #state 1 system is active and we are looking for our target layer z
52 #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
55 with open(filename, "w") as f:
57 lastLayerIndex = 99999
59 for lIndex in xrange(len(lines)):
61 if line.startswith(';'):
62 if line.startswith(';LAYER:'):
63 currentLayer = int(line[7:].strip())
65 if currentLayer < lastLayerIndex:
68 lastLayerIndex = currentLayer
70 layerZ = getPrintZValue(lines[lIndex:lIndex+20])
71 if layerZ >= pauseLevel:
77 x = getValue(line, 'X', x)
78 y = getValue(line, 'Y', y)
81 g = getValue(line, 'G', None)
82 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.
86 f.write(";TYPE:CUSTOM\n")
89 f.write("G1 E-%f F6000\n" % (retractAmount))
92 #Change z before doing the move because the nozzle can hit the glass lock on the UM2
93 if z + moveZ < parkMinZ:
95 f.write("G1 Z%f F300\n" % (parkMinZ))
99 maxZ = profile.getMachineSettingFloat('machine_height') - 10 #For Safety Leave a 10mm space (endstop)
105 f.write("G1 Z%f F300\n" % (newZ))
108 f.write("G1 X%f Y%f F9000\n" % (parkX, parkY))
110 #Disable the E steppers
112 #Wait till the user continues printing
115 #Re-home the axes, in case the operator has perhaps jostled the printer
120 if parkX > 25: g1 += " X25"
123 if parkY > 25: g1 += " Y25"
125 f.write(g1 + " F9000\n")
128 #Push the filament back, and retract again, the properly primes the nozzle when changing filament.
129 f.write("G1 E%f F6000\n" % (retractAmount))
130 f.write("G1 E-%f F6000\n" % (retractAmount))
132 #Move the head back. Move Z at the same time to prevent hitting the glass locks on the UM2
134 f.write("G1 X%f Y%f Z%f F9000\n" % (x, y, z))
136 f.write("G1 X%f Y%f F9000\n" % (x, y))
138 f.write("G1 E%f F6000\n" % (retractAmount))
139 f.write("G1 F9000\n")