mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Simplify indentation of pause at height script
Instead of making lots of nested if statements, use the if statements as an interruption check. This reduces the indentation a lot and makes it easier to read in my opinion. It also makes it easier to add stuff to these checks.
This commit is contained in:
parent
b44854d19d
commit
cfdde8dd07
1 changed files with 86 additions and 82 deletions
|
@ -102,7 +102,6 @@ class PauseAtHeight(Script):
|
||||||
|
|
||||||
x = 0.
|
x = 0.
|
||||||
y = 0.
|
y = 0.
|
||||||
current_z = 0.
|
|
||||||
pause_height = self.getSettingValueByKey("pause_height")
|
pause_height = self.getSettingValueByKey("pause_height")
|
||||||
retraction_amount = self.getSettingValueByKey("retraction_amount")
|
retraction_amount = self.getSettingValueByKey("retraction_amount")
|
||||||
retraction_speed = self.getSettingValueByKey("retraction_speed")
|
retraction_speed = self.getSettingValueByKey("retraction_speed")
|
||||||
|
@ -132,90 +131,95 @@ class PauseAtHeight(Script):
|
||||||
if not layers_started:
|
if not layers_started:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if self.getValue(line, 'G') == 1 or self.getValue(line, 'G') == 0:
|
if self.getValue(line, 'G') != 1 and self.getValue(line, 'G') != 0:
|
||||||
current_z = self.getValue(line, 'Z')
|
continue
|
||||||
if not got_first_g_cmd_on_layer_0:
|
|
||||||
layer_0_z = current_z
|
|
||||||
got_first_g_cmd_on_layer_0 = True
|
|
||||||
|
|
||||||
x = self.getValue(line, 'X', x)
|
current_z = self.getValue(line, 'Z')
|
||||||
y = self.getValue(line, 'Y', y)
|
if not got_first_g_cmd_on_layer_0:
|
||||||
if current_z is not None:
|
layer_0_z = current_z
|
||||||
current_height = current_z - layer_0_z
|
got_first_g_cmd_on_layer_0 = True
|
||||||
if current_height >= pause_height:
|
|
||||||
index = data.index(layer)
|
|
||||||
prevLayer = data[index - 1]
|
|
||||||
prevLines = prevLayer.split("\n")
|
|
||||||
current_e = 0.
|
|
||||||
for prevLine in reversed(prevLines):
|
|
||||||
current_e = self.getValue(prevLine, 'E', -1)
|
|
||||||
if current_e >= 0:
|
|
||||||
break
|
|
||||||
|
|
||||||
# include a number of previous layers
|
x = self.getValue(line, 'X', x)
|
||||||
for i in range(1, redo_layers + 1):
|
y = self.getValue(line, 'Y', y)
|
||||||
prevLayer = data[index - i]
|
if current_z is None:
|
||||||
layer = prevLayer + layer
|
continue
|
||||||
|
|
||||||
prepend_gcode = ";TYPE:CUSTOM\n"
|
current_height = current_z - layer_0_z
|
||||||
prepend_gcode += ";added code by post processing\n"
|
if current_height < pause_height:
|
||||||
prepend_gcode += ";script: PauseAtHeight.py\n"
|
break #Try the next layer.
|
||||||
prepend_gcode += ";current z: %f \n" % current_z
|
|
||||||
prepend_gcode += ";current height: %f \n" % current_height
|
|
||||||
|
|
||||||
# Retraction
|
index = data.index(layer)
|
||||||
prepend_gcode += "M83\n"
|
prevLayer = data[index - 1]
|
||||||
if retraction_amount != 0:
|
prevLines = prevLayer.split("\n")
|
||||||
prepend_gcode += "G1 E-%f F%f\n" % (retraction_amount, retraction_speed * 60)
|
current_e = 0.
|
||||||
|
for prevLine in reversed(prevLines):
|
||||||
# Move the head away
|
current_e = self.getValue(prevLine, 'E', -1)
|
||||||
prepend_gcode += "G1 Z%f F300\n" % (current_z + 1)
|
if current_e >= 0:
|
||||||
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"
|
|
||||||
|
|
||||||
# Set extruder standby temperature
|
|
||||||
prepend_gcode += "M104 S%i; standby temperature\n" % (standby_temperature)
|
|
||||||
|
|
||||||
# Wait till the user continues printing
|
|
||||||
prepend_gcode += "M0 ;Do the actual pause\n"
|
|
||||||
|
|
||||||
# Set extruder resume temperature
|
|
||||||
prepend_gcode += "M109 S%i; resume temperature\n" % (resume_temperature)
|
|
||||||
|
|
||||||
# Push the filament back,
|
|
||||||
if retraction_amount != 0:
|
|
||||||
prepend_gcode += "G1 E%f F%f\n" % (retraction_amount, retraction_speed * 60)
|
|
||||||
|
|
||||||
# Optionally extrude material
|
|
||||||
if extrude_amount != 0:
|
|
||||||
prepend_gcode += "G1 E%f F%f\n" % (extrude_amount, extrude_speed * 60)
|
|
||||||
|
|
||||||
# and retract again, the properly primes the nozzle
|
|
||||||
# when changing filament.
|
|
||||||
if retraction_amount != 0:
|
|
||||||
prepend_gcode += "G1 E-%f F%f\n" % (retraction_amount, retraction_speed * 60)
|
|
||||||
|
|
||||||
# Move the head back
|
|
||||||
prepend_gcode += "G1 Z%f F300\n" % (current_z + 1)
|
|
||||||
prepend_gcode += "G1 X%f Y%f F9000\n" % (x, y)
|
|
||||||
if retraction_amount != 0:
|
|
||||||
prepend_gcode += "G1 E%f F%f\n" % (retraction_amount, retraction_speed * 60)
|
|
||||||
prepend_gcode += "G1 F9000\n"
|
|
||||||
prepend_gcode += "M82\n"
|
|
||||||
|
|
||||||
# reset extrude value to pre pause value
|
|
||||||
prepend_gcode += "G92 E%f\n" % (current_e)
|
|
||||||
|
|
||||||
layer = prepend_gcode + layer
|
|
||||||
|
|
||||||
|
|
||||||
# Override the data of this layer with the
|
|
||||||
# modified data
|
|
||||||
data[index] = layer
|
|
||||||
return data
|
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# include a number of previous layers
|
||||||
|
for i in range(1, redo_layers + 1):
|
||||||
|
prevLayer = data[index - i]
|
||||||
|
layer = prevLayer + layer
|
||||||
|
|
||||||
|
prepend_gcode = ";TYPE:CUSTOM\n"
|
||||||
|
prepend_gcode += ";added code by post processing\n"
|
||||||
|
prepend_gcode += ";script: PauseAtHeight.py\n"
|
||||||
|
prepend_gcode += ";current z: %f \n" % current_z
|
||||||
|
prepend_gcode += ";current height: %f \n" % current_height
|
||||||
|
|
||||||
|
# Retraction
|
||||||
|
prepend_gcode += "M83\n"
|
||||||
|
if retraction_amount != 0:
|
||||||
|
prepend_gcode += "G1 E-%f F%f\n" % (retraction_amount, retraction_speed * 60)
|
||||||
|
|
||||||
|
# Move the head away
|
||||||
|
prepend_gcode += "G1 Z%f F300\n" % (current_z + 1)
|
||||||
|
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"
|
||||||
|
|
||||||
|
# Set extruder standby temperature
|
||||||
|
prepend_gcode += "M104 S%i; standby temperature\n" % (standby_temperature)
|
||||||
|
|
||||||
|
# Wait till the user continues printing
|
||||||
|
prepend_gcode += "M0 ;Do the actual pause\n"
|
||||||
|
|
||||||
|
# Set extruder resume temperature
|
||||||
|
prepend_gcode += "M109 S%i; resume temperature\n" % (resume_temperature)
|
||||||
|
|
||||||
|
# Push the filament back,
|
||||||
|
if retraction_amount != 0:
|
||||||
|
prepend_gcode += "G1 E%f F%f\n" % (retraction_amount, retraction_speed * 60)
|
||||||
|
|
||||||
|
# Optionally extrude material
|
||||||
|
if extrude_amount != 0:
|
||||||
|
prepend_gcode += "G1 E%f F%f\n" % (extrude_amount, extrude_speed * 60)
|
||||||
|
|
||||||
|
# and retract again, the properly primes the nozzle
|
||||||
|
# when changing filament.
|
||||||
|
if retraction_amount != 0:
|
||||||
|
prepend_gcode += "G1 E-%f F%f\n" % (retraction_amount, retraction_speed * 60)
|
||||||
|
|
||||||
|
# Move the head back
|
||||||
|
prepend_gcode += "G1 Z%f F300\n" % (current_z + 1)
|
||||||
|
prepend_gcode += "G1 X%f Y%f F9000\n" % (x, y)
|
||||||
|
if retraction_amount != 0:
|
||||||
|
prepend_gcode += "G1 E%f F%f\n" % (retraction_amount, retraction_speed * 60)
|
||||||
|
prepend_gcode += "G1 F9000\n"
|
||||||
|
prepend_gcode += "M82\n"
|
||||||
|
|
||||||
|
# reset extrude value to pre pause value
|
||||||
|
prepend_gcode += "G92 E%f\n" % (current_e)
|
||||||
|
|
||||||
|
layer = prepend_gcode + layer
|
||||||
|
|
||||||
|
|
||||||
|
# Override the data of this layer with the
|
||||||
|
# modified data
|
||||||
|
data[index] = layer
|
||||||
|
return data
|
||||||
return data
|
return data
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue