forked from nallath/PostProcessingPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPauseAtHeight.py
99 lines (93 loc) · 4.23 KB
/
PauseAtHeight.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from ..Script import Script
class PauseAtHeight(Script):
def __init__(self):
super().__init__()
def getSettingData(self):
return {
"label":"Pause at height",
"key": "PauseAtHeight",
"settings":
{
"pause_height":
{
"label": "Pause height",
"description": "At what height should the pause occur",
"unit": "mm",
"type": "float",
"default": 5.0,
"visible": True
},
"head_park_x":
{
"label": "Head park X",
"description": "What x location does the head move to when pausing.",
"unit": "mm",
"type": "float",
"default": 190,
"visible": True
},
"head_park_y":
{
"label": "Head park Y",
"description": "What y location does the head move to when pausing.",
"unit": "mm",
"type": "float",
"default": 190,
"visible": True
},
"retraction_ammount":
{
"label": "Retraction",
"description": "How much fillament must be retracted at pause.",
"unit": "mm",
"type": "float",
"default": 0,
"visible": True
}
}
}
def execute(self, data):
x = 0.
y = 0.
current_z = 0.
pause_z = self.getSettingValueByKey("pause_height")
retraction_ammount = self.getSettingValueByKey("retraction_ammount")
park_x = self.getSettingValueByKey("head_park_x")
park_y = self.getSettingValueByKey("head_park_y")
for layer in data:
lines = layer.split("\n")
for line in lines:
if self.getValue(line, 'G') == 1 or self.getValue(line, 'G') == 0:
current_z = self.getValue(line, 'Z')
x = self.getValue(line, 'X', x)
y = self.getValue(line, 'Y', y)
if current_z != None:
if current_z >= pause_z:
prepend_gcode = ";TYPE:CUSTOM\n"
#Retraction
prepend_gcode += "M83\n"
prepend_gcode += "G1 E-%f F6000\n" % (retraction_ammount)
#Move the head away
prepend_gcode += "G1 X%f Y%f F9000\n" % (park_x, park_y)
if current_z < 15:
prepend_gcode += "G1 Z15 F300\n"
#Disable the E steppers
prepend_gcode += "M84 E0\n"
#Wait till the user continues printing
prepend_gcode += "@pause ;M0\n"
#Push the filament back, and retract again, the properly primes the nozzle when changing filament.
prepend_gcode += "G1 E%f F6000\n" % (retraction_ammount)
prepend_gcode += "G1 E-%f F6000\n" % (retraction_ammount)
#Move the head back
if current_z < 15:
prepend_gcode += "G1 Z%f F300\n" % (current_z + 1)
prepend_gcode +="G1 X%f Y%f F9000\n" % (x, y)
prepend_gcode +="G1 E%f F6000\n" % (retraction_ammount)
prepend_gcode +="G1 F9000\n"
prepend_gcode +="M82\n"
index = data.index(layer)
layer = prepend_gcode + layer
data[index] = layer #Override the data of this layer with the modified data
return data
break
return data