Advertisement
bobstro

Slic3r bump fan post processing script

May 13th, 2021
737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. #!/usr/bin/python
  2. import sys
  3. import re
  4. import os
  5.  
  6. sourceFile=sys.argv[1]
  7.  
  8. # Read the ENTIRE g-code file into memory
  9. with open(sourceFile, "r") as f:
  10.     lines = f.readlines()
  11.  
  12. destFile = re.sub('\.gcode$','',sourceFile)
  13. os.rename(sourceFile,destFile+".bumpfan.bak")
  14. destFile = re.sub('\.gcode$','',sourceFile)
  15. destFile = destFile + '.gcode'
  16.  
  17. with open(destFile, "w") as of:
  18.     for lIndex in xrange(len(lines)):
  19.         oline = lines[lIndex]
  20.         # Parse gcode line
  21.         parts = oline.split(';', 1)
  22.         if len(parts) > 0:
  23.             # Parse command
  24.             command = parts[0].strip()
  25.  
  26.             if command:
  27.                 stringMatch = re.search ('^M106 S(.*)', command)
  28.                 if stringMatch:
  29.                     # Insert code to bump fan to max before fan speed commands
  30.                     of.write('M106 S255\n')
  31.            
  32.             # Write original line      
  33.             of.write(oline)
  34. of.close()
  35. f.close()
  36.  
  37.  
  38.  
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement