I am post-processing output from a python script that generates GCODE for my homebrew pen plotter.
The post-processor adds a white space in my GCODE right after a crucial bit of information (after every X and Y coordinate value), causing the GCODE to become invalid.
Example of how it should look:
Example of how my output looks:
I have tried to remove the \s operators from the suspected pieces of code, I have tried using .lstrip() in various areas to remove the white spaces but to no avail. I have also removed all double spaces that were present in the code, and nothing has helped so far.
I suspect this code is doing it:
def round_coordinates(self,parameters) :
try:
round_ = int(parameters)
except :
self.error("Bad parameters for round. Round should be an integer! \n(Parameters: '%s')"%(parameters), "error")
gcode = ""
for s in self.gcode.split("\n"):
for a in "xyzijkaf" :
r = re.search(r"(?i)("+a+r")\s*(-?\s*(\d*\.?\d*))", s)
if r :
if r.group(2)!="":
s = re.sub(
r"(?i)("+a+r")\s*(-?)\s*(\d*\.?\d*)",
(r"\1 %0."+str(round_)+"f" if round_>0 else r"\1 %d")%round(float(r.group(2)),round_),
s)
gcode += s + "\n"
self.gcode = gcode
I am hoping to be able to find out where the whitespace comes from, I may not showing the right bit of code so I have linked the source file. It appears at line 2648 and at line 5440 there is also a round function present that seems to be related.
Here is a pastebin to the complete code: https://pastebin.com/s8J1H8r6