diff --git a/plugins/PostProcessingPlugin/Script.py b/plugins/PostProcessingPlugin/Script.py index 7d603ba11f..7f419cd422 100644 --- a/plugins/PostProcessingPlugin/Script.py +++ b/plugins/PostProcessingPlugin/Script.py @@ -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): diff --git a/plugins/PostProcessingPlugin/scripts/PauseAtHeight.py b/plugins/PostProcessingPlugin/scripts/PauseAtHeight.py index 10de2fa318..805ab0a2c3 100644 --- a/plugins/PostProcessingPlugin/scripts/PauseAtHeight.py +++ b/plugins/PostProcessingPlugin/scripts/PauseAtHeight.py @@ -174,15 +174,12 @@ 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") @@ -222,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 diff --git a/plugins/SupportEraser/SupportEraser.py b/plugins/SupportEraser/SupportEraser.py index 9e2d41014d..4e55702687 100644 --- a/plugins/SupportEraser/SupportEraser.py +++ b/plugins/SupportEraser/SupportEraser.py @@ -1,6 +1,6 @@ # Copyright (c) 2018 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. - +from UM.Math.Vector import Vector from UM.Tool import Tool from PyQt5.QtCore import Qt, QUrl from UM.Application import Application @@ -41,6 +41,9 @@ class SupportEraser(Tool): mesh = MeshBuilder() mesh.addCube(10,10,10) node.setMeshData(mesh.build()) + # Place the cube in the platform. Do it manually so it works if the "automatic drop models" is OFF + move_vector = Vector(0, 5, 0) + node.setPosition(move_vector) active_build_plate = Application.getInstance().getBuildPlateModel().activeBuildPlate