Prusa slicer gcode script to allow preview

pull/25/head
ThomasToka 10 months ago committed by GitHub
parent 70c0cbd5b9
commit 876b7fb608
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,42 @@
#!/usr/bin/env python3
#
# Prusa Slicer remove headers before jpg.
#
# This script has been developed for E3S1PROFORKBYTT by Thomas Toka.
#
#
# ------------------------------------------------------------------------------
import sys
import os
# Get the g-code source file name
sourceFile = sys.argv[1]
# Read the ENTIRE g-code file into memory
with open(sourceFile, "r") as f:
lines = f.readlines()
new_lines = []
remove_next_line = False
for line in lines:
if remove_next_line and line.strip() == ';':
remove_next_line = False
continue
if line.startswith('; generated by PrusaSlicer'):
remove_next_line = True
elif remove_next_line and line.strip() == '':
continue
else:
new_lines.append(line)
try:
with open(sourceFile, "w+") as of:
of.write(''.join(new_lines))
except:
print('Error writing output file')
input()
finally:
of.close()
f.close()
Loading…
Cancel
Save