FullControlXYZ / fullcontrol

Python version of FullControl for toolpath design (and more) - the readme below is best source of information
GNU General Public License v3.0
672 stars 78 forks source link

Fix blank lines in GCode on Windows #54

Closed conifarad closed 11 months ago

conifarad commented 11 months ago

The issue: When saving GCode on Windows (using save_as in GcodeControls), FullControl puts unnecessary blank lines between commands.

The cause: In the gcode() function, GCode lines are joined with os.linesep, which on Windows is \r\n. Python's write function by default replaces \n with os.linesep, so \r\n is written to the file as \r\r\n. Text editors interpret this as two line breaks, so display a blank line. Since hardcoded multiline comments are already joined with \n, these are translated correctly as \r\n when written to a file.

The solution: I changed os.linesep to '\n' in the gcode() functions. Now the GCode returned from transform will consistently use \n for line breaks, and the gcode written to the file will use the correct platform-dependent line breaks (\r\n on Windows). I haven't tested the code for four-axis or five-axis, but I'm assuming it will work the same.

Here are some sample before and after snippets:

Before

;FLAVOR:Marlin
;TIME:0
;Filament used: 0m
;Layer height: 0
;MINX:0
;MINY:0
;MINZ:0

;MAXX:220
;MAXY:220
;MAXZ:250

; Time to print!!!!!
; GCode created with FullControl - tell us what you're printing!
; info@fullcontrol.xyz or tag FullControlXYZ on Twitter/Instagram/LinkedIn/Reddit/TikTok 

G28 ; home axes

M140 S40 ; set bed temp and continue

M105

M104 S210 ; set hotend temp and continue

M190 S40 ; set bed temp and wait

; and so on

After

;FLAVOR:Marlin
;TIME:0
;Filament used: 0m
;Layer height: 0
;MINX:0
;MINY:0
;MINZ:0
;MAXX:220
;MAXY:220
;MAXZ:250

; Time to print!!!!!
; GCode created with FullControl - tell us what you're printing!
; info@fullcontrol.xyz or tag FullControlXYZ on Twitter/Instagram/LinkedIn/Reddit/TikTok 

G28 ; home axes
M140 S40 ; set bed temp and continue
M105
M104 S210 ; set hotend temp and continue
M190 S40 ; set bed temp and wait
; and so on
RaymondKroon commented 11 months ago

I fixed it the same. Documentation is actually saying you should not use os.linesep when writing to files in text mode: https://docs.python.org/3/library/os.html#os.linesep

fullcontrol-xyz commented 11 months ago

Great, thanks for noticing and fixing this!