Created
March 15, 2024 18:56
-
-
Save qb1/ced2ba98e6ac96b88fc1a68a7bbb7bb7 to your computer and use it in GitHub Desktop.
Sanitize GCode extreme extrusion values
This file contains 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
#!/usr/bin/env python3 | |
# ------------------------------------------------------------------------------ | |
# Orca / Prusa / Super Slicer post-processor script | |
# Remove extreme extrusion values causing blobs on the prime tower when | |
# doing single-extruder multi-material slicing | |
# ------------------------------------------------------------------------------ | |
import sys | |
import re | |
import os | |
import base64 | |
import io | |
import subprocess | |
input_file = sys.argv[1] | |
lines = [] | |
with open(input_file, "r") as f: | |
extrusion_exp = '(G1.*E)(\\d+.\\d+)(.*)' | |
overriding_value = 0.0 | |
for line in f: | |
match = re.findall(extrusion_exp, line) | |
if match: | |
match = match[0] | |
value = float(match[1]) | |
if value > 10: | |
line = f"{match[0]}{overriding_value}{match[2]} ; fixed extrusion" | |
print(f"Replacing extrusion from {match[1]} to {overriding_value}") | |
lines.append(line) | |
lines = ''.join(lines) | |
with open(input_file, "w+") as of: | |
of.write(lines) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment