mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
Fixed double ";" when using putValue on a line with a comment
This commit is contained in:
parent
ea0c8ff9bc
commit
3b4833a7e6
1 changed files with 23 additions and 30 deletions
|
@ -141,52 +141,45 @@ class Script:
|
||||||
All other keyword parameters are put in the result in g-code's format.
|
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
|
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``. 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
|
``G1 X100``. The parameters will be added in order G M T S F X Y Z E.
|
||||||
parameters T and S will be put second (or first if there is no G or M).
|
Any other parameters will be added in arbitrary order.
|
||||||
The rest of the parameters will be put in arbitrary order.
|
|
||||||
|
|
||||||
:param line: The original g-code line that must be modified. If not
|
:param line: The original g-code line that must be modified. If not
|
||||||
provided, an entirely new g-code line will be produced.
|
provided, an entirely new g-code line will be produced.
|
||||||
:return: A line of g-code with the desired parameters filled in.
|
:return: A line of g-code with the desired parameters filled in.
|
||||||
"""
|
"""
|
||||||
|
# Strip the comment.
|
||||||
#Strip the comment.
|
|
||||||
comment = ""
|
|
||||||
if ";" in line:
|
if ";" in line:
|
||||||
comment = line[line.find(";"):]
|
comment = line[line.find(";"):]
|
||||||
line = line[:line.find(";")] #Strip the comment.
|
line = line[:line.find(";")]
|
||||||
|
else:
|
||||||
|
comment = ""
|
||||||
|
|
||||||
#Parse the original g-code line.
|
# Parse the original g-code line and add them to kwargs.
|
||||||
for part in line.split(" "):
|
for part in line.split(" "):
|
||||||
if part == "":
|
if part == "":
|
||||||
continue
|
continue
|
||||||
parameter = part[0]
|
parameter = part[0]
|
||||||
|
if parameter not in kwargs:
|
||||||
|
value = part[1:]
|
||||||
|
kwargs[parameter] = value
|
||||||
|
|
||||||
|
# Start writing the new g-code line.
|
||||||
|
line_parts = list()
|
||||||
|
# First add these parameters in order
|
||||||
|
for parameter in ["G", "M", "T", "S", "F", "X", "Y", "Z", "E"]:
|
||||||
if parameter in kwargs:
|
if parameter in kwargs:
|
||||||
continue #Skip this one. The user-provided parameter overwrites the one in the line.
|
line_parts.append(parameter + str(kwargs.pop(parameter)))
|
||||||
value = part[1:]
|
# Then add the rest of the parameters
|
||||||
kwargs[parameter] = value
|
for parameter, value in kwargs.items():
|
||||||
|
line_parts.append(parameter + str(value))
|
||||||
|
|
||||||
#Write the new g-code line.
|
# If there was a comment, put it at the end.
|
||||||
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 comment != "":
|
||||||
if result != "":
|
line_parts.append(comment)
|
||||||
result += " "
|
|
||||||
result += ";" + comment
|
|
||||||
|
|
||||||
return result
|
# Add spaces and return the new line
|
||||||
|
return " ".join(line_parts)
|
||||||
|
|
||||||
def execute(self, data: List[str]) -> List[str]:
|
def execute(self, data: List[str]) -> List[str]:
|
||||||
"""This is called when the script is executed.
|
"""This is called when the script is executed.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue