Created
August 9, 2022 00:36
-
-
Save sporkus/528dfce9d0f6ef87607cad0e75a8bd6d to your computer and use it in GitHub Desktop.
per feature slicer post-process script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import re | |
import os | |
FASTSCV=120 | |
NORMALSCV=15 | |
BRIDGESCV=8 | |
TOPFLOW=95 #top flow ratio 0-100 | |
sourceFile=sys.argv[1] | |
# Read the ENTIRE g-code file into memory | |
with open(sourceFile, "r") as f: | |
lines = f.readlines() | |
if (sourceFile.endswith('.gcode')): | |
destFile = re.sub('\.gcode$','',sourceFile) | |
try: | |
os.rename(sourceFile, destFile+".sqv.bak") | |
except FileExistsError: | |
os.remove(destFile+".sqv.bak") | |
os.rename(sourceFile, destFile+".sqv.bak") | |
destFile = re.sub('\.gcode$','',sourceFile) | |
destFile = destFile + '.gcode' | |
else: | |
destFile = sourceFile | |
os.remove(sourceFile) | |
with open(destFile, "w") as of: | |
of.write('; Ensure macros are properly setup in klipper\n') | |
for line in lines: | |
# Reset before any feature change | |
if line.startswith(';TYPE'): | |
of.write('M221 S100\n') | |
of.write(f'SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY={NORMALSCV}\n') | |
# Normal write line | |
of.write(line) | |
# Per feature override | |
if line.startswith(';TYPE:Internal infill') or line.startswith(';TYPE:Solid infill'): | |
of.write(f'SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY={FASTSCV}\n') | |
elif line.startswith(';TYPE:Bridge infill'): | |
of.write(f'SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY={BRIDGESCV}\n') | |
elif line.startswith(';TYPE:Top solid infill'): | |
of.write(f'M221 S{TOPFLOW}\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment