mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 14:37:29 -06:00
Merge branch 'master' into refactoring_machine_manager
This commit is contained in:
commit
22cf5abec2
18 changed files with 419 additions and 201 deletions
|
@ -105,6 +105,58 @@ class Script:
|
|||
except:
|
||||
return default
|
||||
|
||||
## Convenience function to produce a line of g-code.
|
||||
#
|
||||
# You can put in an original g-code line and it'll re-use all the values
|
||||
# in that line.
|
||||
# All other keyword parameters are put in the result in g-code's format.
|
||||
# For instance, if you put ``G=1`` in the parameters, it will output
|
||||
# ``G1``. If you put ``G=1, X=100`` in the parameters, it will output
|
||||
# ``G1 X100``. The parameters G and M will always be put first. The
|
||||
# parameters T and S will be put second (or first if there is no G or M).
|
||||
# The rest of the parameters will be put in arbitrary order.
|
||||
# \param line The original g-code line that must be modified. If not
|
||||
# provided, an entirely new g-code line will be produced.
|
||||
# \return A line of g-code with the desired parameters filled in.
|
||||
def putValue(self, line = "", **kwargs):
|
||||
#Strip the comment.
|
||||
comment = ""
|
||||
if ";" in line:
|
||||
comment = line[line.find(";"):]
|
||||
line = line[:line.find(";")] #Strip the comment.
|
||||
|
||||
#Parse the original g-code line.
|
||||
for part in line.split(" "):
|
||||
if part == "":
|
||||
continue
|
||||
parameter = part[0]
|
||||
if parameter in kwargs:
|
||||
continue #Skip this one. The user-provided parameter overwrites the one in the line.
|
||||
value = part[1:]
|
||||
kwargs[parameter] = value
|
||||
|
||||
#Write the new g-code line.
|
||||
result = ""
|
||||
priority_parameters = ["G", "M", "T", "S", "F", "X", "Y", "Z", "E"] #First some parameters that get priority. In order of priority!
|
||||
for priority_key in priority_parameters:
|
||||
if priority_key in kwargs:
|
||||
if result != "":
|
||||
result += " "
|
||||
result += priority_key + str(kwargs[priority_key])
|
||||
del kwargs[priority_key]
|
||||
for key, value in kwargs.items():
|
||||
if result != "":
|
||||
result += " "
|
||||
result += key + str(value)
|
||||
|
||||
#Put the comment back in.
|
||||
if comment != "":
|
||||
if result != "":
|
||||
result += " "
|
||||
result += ";" + comment
|
||||
|
||||
return result
|
||||
|
||||
## This is called when the script is executed.
|
||||
# It gets a list of g-code strings and needs to return a (modified) list.
|
||||
def execute(self, data):
|
||||
|
|
|
@ -174,19 +174,19 @@ class PauseAtHeight(Script):
|
|||
if not line.startswith(";LAYER:"):
|
||||
continue
|
||||
current_layer = line[len(";LAYER:"):]
|
||||
print("----------current_layer:", current_layer)
|
||||
try:
|
||||
current_layer = int(current_layer)
|
||||
except ValueError: #Couldn't cast to int. Something is wrong with this g-code data.
|
||||
print("----------couldn't cast to int")
|
||||
continue
|
||||
if current_layer < pause_layer:
|
||||
break #Try the next layer.
|
||||
print("------------hit! Got it!")
|
||||
|
||||
prevLayer = data[index - 1]
|
||||
prevLines = prevLayer.split("\n")
|
||||
current_e = 0.
|
||||
|
||||
# Access last layer, browse it backwards to find
|
||||
# last extruder absolute position
|
||||
for prevLine in reversed(prevLines):
|
||||
current_e = self.getValue(prevLine, "E", -1)
|
||||
if current_e >= 0:
|
||||
|
@ -197,6 +197,18 @@ class PauseAtHeight(Script):
|
|||
prevLayer = data[index - i]
|
||||
layer = prevLayer + layer
|
||||
|
||||
# Get extruder's absolute position at the
|
||||
# begining of the first layer redone
|
||||
# see https://github.com/nallath/PostProcessingPlugin/issues/55
|
||||
if i == redo_layers:
|
||||
prevLines = prevLayer.split("\n")
|
||||
for line in prevLines:
|
||||
new_e = self.getValue(line, 'E', current_e)
|
||||
|
||||
if new_e != current_e:
|
||||
current_e = new_e
|
||||
break
|
||||
|
||||
prepend_gcode = ";TYPE:CUSTOM\n"
|
||||
prepend_gcode += ";added code by post processing\n"
|
||||
prepend_gcode += ";script: PauseAtHeight.py\n"
|
||||
|
@ -207,51 +219,51 @@ class PauseAtHeight(Script):
|
|||
prepend_gcode += ";current layer: {layer}\n".format(layer = current_layer)
|
||||
|
||||
# Retraction
|
||||
prepend_gcode += "M83\n"
|
||||
prepend_gcode += self.putValue(M = 83) + "\n"
|
||||
if retraction_amount != 0:
|
||||
prepend_gcode += "G1 E-%f F%f\n" % (retraction_amount, retraction_speed * 60)
|
||||
prepend_gcode += self.putValue(G = 1, E = -retraction_amount, F = retraction_speed * 60) + "\n"
|
||||
|
||||
# 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)
|
||||
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"
|
||||
if current_z < 15:
|
||||
prepend_gcode += "G1 Z15 F300\n"
|
||||
prepend_gcode += self.putValue(G = 1, Z = 15, F = 300) + "\n"
|
||||
|
||||
# Disable the E steppers
|
||||
prepend_gcode += "M84 E0\n"
|
||||
prepend_gcode += self.putValue(M = 84, E = 0) + "\n"
|
||||
|
||||
# Set extruder standby temperature
|
||||
prepend_gcode += "M104 S%i; standby temperature\n" % (standby_temperature)
|
||||
prepend_gcode += self.putValue(M = 104, S = standby_temperature) + "; standby temperature\n"
|
||||
|
||||
# Wait till the user continues printing
|
||||
prepend_gcode += "M0 ;Do the actual pause\n"
|
||||
prepend_gcode += self.putValue(M = 0) + ";Do the actual pause\n"
|
||||
|
||||
# Set extruder resume temperature
|
||||
prepend_gcode += "M109 S%i; resume temperature\n" % (resume_temperature)
|
||||
prepend_gcode += self.putValue(M = 109, S = resume_temperature) + "; resume temperature\n"
|
||||
|
||||
# Push the filament back,
|
||||
if retraction_amount != 0:
|
||||
prepend_gcode += "G1 E%f F%f\n" % (retraction_amount, retraction_speed * 60)
|
||||
prepend_gcode += self.putValue(G = 1, E = retraction_amount, F = retraction_speed * 60) + "\n"
|
||||
|
||||
# Optionally extrude material
|
||||
if extrude_amount != 0:
|
||||
prepend_gcode += "G1 E%f F%f\n" % (extrude_amount, extrude_speed * 60)
|
||||
prepend_gcode += self.putValue(G = 1, E = extrude_amount, F = extrude_speed * 60) + "\n"
|
||||
|
||||
# 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)
|
||||
prepend_gcode += self.putValue(G = 1, E = -retraction_amount, F = retraction_speed * 60) + "\n"
|
||||
|
||||
# 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)
|
||||
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"
|
||||
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"
|
||||
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(M = 82) + "\n"
|
||||
|
||||
# reset extrude value to pre pause value
|
||||
prepend_gcode += "G92 E%f\n" % (current_e)
|
||||
prepend_gcode += self.putValue(G = 92, E = current_e) + "\n"
|
||||
|
||||
layer = prepend_gcode + layer
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue