Last active
October 26, 2018 00:56
-
-
Save vertigo235/2b3d2eef1ceafe65ee42b2633e84c37e to your computer and use it in GitHub Desktop.
Lowers hotend on ramming, must include ; RAMMING_TEMP: XXX in filament start gcode
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 python | |
import fileinput | |
import re | |
ramming_temp_pattern = re.compile(r'\;\s+RAMMING_TEMP:\s+([0-9]{1,3})') | |
tool_unload_pattern = re.compile(r'(\; CP TOOLCHANGE UNLOAD\n)') | |
tool_load_pattern = re.compile(r'(\; CP TOOLCHANGE LOAD\n)') | |
temp_pattern = re.compile(r'M104 S([0-9]{1,3})') | |
empty_grid_pattern = re.compile(r'\; CP TOOLCHANGE END\n') | |
curtemp = '' | |
ramming_temp = '' | |
for line in fileinput.input(inplace=True, backup='.bak'): | |
temp = temp_pattern.search(line) | |
clear_ramming_temp = empty_grid_pattern.search(line) | |
ramming_temp_search = ramming_temp_pattern.search(line) | |
if temp: | |
curtemp = int(temp.group(1)) | |
if ramming_temp_search: | |
ramming_temp = int(ramming_temp_search.group(1)) | |
if clear_ramming_temp: | |
ramming_temp = None | |
if tool_unload_pattern.search(line) and ramming_temp: | |
print tool_unload_pattern.sub(r'\1M104 S%s; Set ramming temp\n' % ramming_temp, line), | |
elif tool_load_pattern.search(line) and ramming_temp: | |
print tool_load_pattern.sub(r'\1M104 S%s; Return to printing temp\n' % curtemp, line), | |
else: | |
print line, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment