Skip to content

Instantly share code, notes, and snippets.

@qb1
Created March 15, 2024 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qb1/ced2ba98e6ac96b88fc1a68a7bbb7bb7 to your computer and use it in GitHub Desktop.
Save qb1/ced2ba98e6ac96b88fc1a68a7bbb7bb7 to your computer and use it in GitHub Desktop.
Sanitize GCode extreme extrusion values
#!/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