mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-09 07:56:22 -06:00
Merge pull request #3648 from JPFrancoia/master
Bug fixes and improvements for PauseAtHeight plugin
This commit is contained in:
commit
7d0b664c53
1 changed files with 83 additions and 31 deletions
|
@ -117,6 +117,28 @@ class PauseAtHeight(Script):
|
||||||
}
|
}
|
||||||
}"""
|
}"""
|
||||||
|
|
||||||
|
|
||||||
|
def getNextXY(self, layer: str):
|
||||||
|
|
||||||
|
"""
|
||||||
|
Get the X and Y values for a layer (will be used to get X and Y of
|
||||||
|
the layer after the pause
|
||||||
|
"""
|
||||||
|
|
||||||
|
lines = layer.split("\n")
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
|
||||||
|
if self.getValue(line, "X") is not None and self.getValue(line, "Y") is not None:
|
||||||
|
|
||||||
|
x = self.getValue(line, "X")
|
||||||
|
y = self.getValue(line, "Y")
|
||||||
|
|
||||||
|
return (x, y)
|
||||||
|
|
||||||
|
return (0, 0)
|
||||||
|
|
||||||
|
|
||||||
def execute(self, data: list):
|
def execute(self, data: list):
|
||||||
|
|
||||||
"""data is a list. Each index contains a layer"""
|
"""data is a list. Each index contains a layer"""
|
||||||
|
@ -138,48 +160,72 @@ class PauseAtHeight(Script):
|
||||||
resume_temperature = self.getSettingValueByKey("resume_temperature")
|
resume_temperature = self.getSettingValueByKey("resume_temperature")
|
||||||
|
|
||||||
# T = ExtruderManager.getInstance().getActiveExtruderStack().getProperty("material_print_temperature", "value")
|
# T = ExtruderManager.getInstance().getActiveExtruderStack().getProperty("material_print_temperature", "value")
|
||||||
# with open("out.txt", "w") as f:
|
|
||||||
# f.write(T)
|
|
||||||
|
|
||||||
# use offset to calculate the current height: <current_height> = <current_z> - <layer_0_z>
|
# use offset to calculate the current height: <current_height> = <current_z> - <layer_0_z>
|
||||||
layer_0_z = 0.
|
layer_0_z = 0.
|
||||||
current_z = 0
|
current_z = 0
|
||||||
got_first_g_cmd_on_layer_0 = False
|
got_first_g_cmd_on_layer_0 = False
|
||||||
|
|
||||||
|
nbr_negative_layers = 0
|
||||||
|
|
||||||
for index, layer in enumerate(data):
|
for index, layer in enumerate(data):
|
||||||
lines = layer.split("\n")
|
lines = layer.split("\n")
|
||||||
|
|
||||||
|
# Scroll each line of instruction for each layer in the G-code
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
|
||||||
|
# Fist positive layer reached
|
||||||
if ";LAYER:0" in line:
|
if ";LAYER:0" in line:
|
||||||
layers_started = True
|
layers_started = True
|
||||||
|
|
||||||
|
# Count nbr of negative layers (raft)
|
||||||
|
elif ";LAYER:-" in line:
|
||||||
|
nbr_negative_layers += 1
|
||||||
|
|
||||||
if not layers_started:
|
if not layers_started:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# If a Z instruction is in the line, read the current Z
|
||||||
if self.getValue(line, "Z") is not None:
|
if self.getValue(line, "Z") is not None:
|
||||||
current_z = self.getValue(line, "Z")
|
current_z = self.getValue(line, "Z")
|
||||||
|
|
||||||
if pause_at == "height":
|
if pause_at == "height":
|
||||||
|
|
||||||
|
# Ignore if the line is not G1 or G0
|
||||||
if self.getValue(line, "G") != 1 and self.getValue(line, "G") != 0:
|
if self.getValue(line, "G") != 1 and self.getValue(line, "G") != 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# This block is executed once, the first time there is a G
|
||||||
|
# command, to get the z offset (z for first positive layer)
|
||||||
if not got_first_g_cmd_on_layer_0:
|
if not got_first_g_cmd_on_layer_0:
|
||||||
layer_0_z = current_z
|
layer_0_z = current_z
|
||||||
got_first_g_cmd_on_layer_0 = True
|
got_first_g_cmd_on_layer_0 = True
|
||||||
|
|
||||||
x = self.getValue(line, "X", x)
|
|
||||||
y = self.getValue(line, "Y", y)
|
|
||||||
|
|
||||||
current_height = current_z - layer_0_z
|
current_height = current_z - layer_0_z
|
||||||
|
|
||||||
if current_height < pause_height:
|
if current_height < pause_height:
|
||||||
break #Try the next layer.
|
break # Try the next layer.
|
||||||
else: #Pause at layer.
|
|
||||||
|
# Pause at layer
|
||||||
|
else:
|
||||||
|
|
||||||
if not line.startswith(";LAYER:"):
|
if not line.startswith(";LAYER:"):
|
||||||
continue
|
continue
|
||||||
current_layer = line[len(";LAYER:"):]
|
current_layer = line[len(";LAYER:"):]
|
||||||
try:
|
try:
|
||||||
current_layer = int(current_layer)
|
current_layer = int(current_layer)
|
||||||
except ValueError: #Couldn't cast to int. Something is wrong with this g-code data.
|
|
||||||
|
# Couldn't cast to int. Something is wrong with this
|
||||||
|
# g-code data
|
||||||
|
except ValueError:
|
||||||
continue
|
continue
|
||||||
if current_layer < pause_layer:
|
if current_layer < pause_layer - nbr_negative_layers:
|
||||||
break #Try the next layer.
|
continue
|
||||||
|
|
||||||
|
# Get X and Y from the next layer (better position for
|
||||||
|
# the nozzle)
|
||||||
|
nextLayer = data[index + 1]
|
||||||
|
x, y = self.getNextXY(nextLayer)
|
||||||
|
|
||||||
prevLayer = data[index - 1]
|
prevLayer = data[index - 1]
|
||||||
prevLines = prevLayer.split("\n")
|
prevLines = prevLayer.split("\n")
|
||||||
|
@ -201,6 +247,9 @@ class PauseAtHeight(Script):
|
||||||
# begining of the first layer redone
|
# begining of the first layer redone
|
||||||
# see https://github.com/nallath/PostProcessingPlugin/issues/55
|
# see https://github.com/nallath/PostProcessingPlugin/issues/55
|
||||||
if i == redo_layers:
|
if i == redo_layers:
|
||||||
|
# Get X and Y from the next layer (better position for
|
||||||
|
# the nozzle)
|
||||||
|
x, y = self.getNextXY(layer)
|
||||||
prevLines = prevLayer.split("\n")
|
prevLines = prevLayer.split("\n")
|
||||||
for line in prevLines:
|
for line in prevLines:
|
||||||
new_e = self.getValue(line, 'E', current_e)
|
new_e = self.getValue(line, 'E', current_e)
|
||||||
|
@ -213,57 +262,60 @@ class PauseAtHeight(Script):
|
||||||
prepend_gcode += ";added code by post processing\n"
|
prepend_gcode += ";added code by post processing\n"
|
||||||
prepend_gcode += ";script: PauseAtHeight.py\n"
|
prepend_gcode += ";script: PauseAtHeight.py\n"
|
||||||
if pause_at == "height":
|
if pause_at == "height":
|
||||||
prepend_gcode += ";current z: {z}\n".format(z = current_z)
|
prepend_gcode += ";current z: {z}\n".format(z=current_z)
|
||||||
prepend_gcode += ";current height: {height}\n".format(height = current_height)
|
prepend_gcode += ";current height: {height}\n".format(height=current_height)
|
||||||
else:
|
else:
|
||||||
prepend_gcode += ";current layer: {layer}\n".format(layer = current_layer)
|
prepend_gcode += ";current layer: {layer}\n".format(layer=current_layer)
|
||||||
|
|
||||||
# Retraction
|
# Retraction
|
||||||
prepend_gcode += self.putValue(M = 83) + "\n"
|
prepend_gcode += self.putValue(M=83) + "\n"
|
||||||
if retraction_amount != 0:
|
if retraction_amount != 0:
|
||||||
prepend_gcode += self.putValue(G = 1, E = -retraction_amount, F = retraction_speed * 60) + "\n"
|
prepend_gcode += self.putValue(G=1, E=-retraction_amount, F=retraction_speed * 60) + "\n"
|
||||||
|
|
||||||
# Move the head away
|
# Move the head away
|
||||||
prepend_gcode += self.putValue(G = 1, Z = current_z + 1, F = 300) + "\n"
|
prepend_gcode += self.putValue(G=1, Z=current_z + 1, F=300) + "\n"
|
||||||
prepend_gcode += self.putValue(G = 1, X = park_x, Y = park_y, F = 9000) + "\n"
|
|
||||||
|
# This line should be ok
|
||||||
|
prepend_gcode += self.putValue(G=1, X=park_x, Y=park_y, F=9000) + "\n"
|
||||||
|
|
||||||
if current_z < 15:
|
if current_z < 15:
|
||||||
prepend_gcode += self.putValue(G = 1, Z = 15, F = 300) + "\n"
|
prepend_gcode += self.putValue(G=1, Z=15, F=300) + "\n"
|
||||||
|
|
||||||
# Disable the E steppers
|
# Disable the E steppers
|
||||||
prepend_gcode += self.putValue(M = 84, E = 0) + "\n"
|
prepend_gcode += self.putValue(M=84, E=0) + "\n"
|
||||||
|
|
||||||
# Set extruder standby temperature
|
# Set extruder standby temperature
|
||||||
prepend_gcode += self.putValue(M = 104, S = standby_temperature) + "; standby temperature\n"
|
prepend_gcode += self.putValue(M=104, S=standby_temperature) + "; standby temperature\n"
|
||||||
|
|
||||||
# Wait till the user continues printing
|
# Wait till the user continues printing
|
||||||
prepend_gcode += self.putValue(M = 0) + ";Do the actual pause\n"
|
prepend_gcode += self.putValue(M=0) + ";Do the actual pause\n"
|
||||||
|
|
||||||
# Set extruder resume temperature
|
# Set extruder resume temperature
|
||||||
prepend_gcode += self.putValue(M = 109, S = resume_temperature) + "; resume temperature\n"
|
prepend_gcode += self.putValue(M=109, S=resume_temperature) + "; resume temperature\n"
|
||||||
|
|
||||||
# Push the filament back,
|
# Push the filament back,
|
||||||
if retraction_amount != 0:
|
if retraction_amount != 0:
|
||||||
prepend_gcode += self.putValue(G = 1, E = retraction_amount, F = retraction_speed * 60) + "\n"
|
prepend_gcode += self.putValue(G=1, E=retraction_amount, F=retraction_speed * 60) + "\n"
|
||||||
|
|
||||||
# Optionally extrude material
|
# Optionally extrude material
|
||||||
if extrude_amount != 0:
|
if extrude_amount != 0:
|
||||||
prepend_gcode += self.putValue(G = 1, E = extrude_amount, F = extrude_speed * 60) + "\n"
|
prepend_gcode += self.putValue(G=1, E=extrude_amount, F=extrude_speed * 60) + "\n"
|
||||||
|
|
||||||
# and retract again, the properly primes the nozzle
|
# and retract again, the properly primes the nozzle
|
||||||
# when changing filament.
|
# when changing filament.
|
||||||
if retraction_amount != 0:
|
if retraction_amount != 0:
|
||||||
prepend_gcode += self.putValue(G = 1, E = -retraction_amount, F = retraction_speed * 60) + "\n"
|
prepend_gcode += self.putValue(G=1, E=-retraction_amount, F=retraction_speed * 60) + "\n"
|
||||||
|
|
||||||
# Move the head back
|
# Move the head back
|
||||||
prepend_gcode += self.putValue(G = 1, Z = current_z + 1, F = 300) + "\n"
|
prepend_gcode += self.putValue(G=1, Z=current_z + 1, F=300) + "\n"
|
||||||
prepend_gcode += self.putValue(G = 1, X = x, Y = y, F = 9000) + "\n"
|
prepend_gcode += self.putValue(G=1, X=x, Y=y, F=9000) + "\n"
|
||||||
if retraction_amount != 0:
|
if retraction_amount != 0:
|
||||||
prepend_gcode += self.putValue(G = 1, E = retraction_amount, F = retraction_speed * 60) + "\n"
|
prepend_gcode += self.putValue(G=1, E=retraction_amount, F=retraction_speed * 60) + "\n"
|
||||||
prepend_gcode += self.putValue(G = 1, F = 9000) + "\n"
|
prepend_gcode += self.putValue(G=1, F=9000) + "\n"
|
||||||
prepend_gcode += self.putValue(M = 82) + "\n"
|
prepend_gcode += self.putValue(M=82) + "\n"
|
||||||
|
|
||||||
# reset extrude value to pre pause value
|
# reset extrude value to pre pause value
|
||||||
prepend_gcode += self.putValue(G = 92, E = current_e) + "\n"
|
prepend_gcode += self.putValue(G=92, E=current_e) + "\n"
|
||||||
|
|
||||||
layer = prepend_gcode + layer
|
layer = prepend_gcode + layer
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue