# Copyright (c) 2017 Ruben Dulek # Copyright © 2019 Jeff Epler # Fix T-numbers in temperature commands for Qidi Tech I with GPX # # My best understanding of the problem is this: # # Cura thinks that "T#" is modal only when it is the only (first?) thing # on a line, while GPX thinks that e.g., "M109 T1 S200" contains a modal # "T1". # # This causes dual extrusion code to send temperature commands to the wrong # nozzle. # # This script attempts to work around the problem by tracking which "T#" lines # Cura thinks are modal, and then attaching that "T#" again to any M104/M109 # lines that would require it. # # What seems incomplete about this story is, cura writes extrusions as "E#", # which should also be moving the "T#" extruder motor. But GPX doesn't start # extruding T0 with the sequence # # T1 # M104 T0 S175 # G1 F1500 E-0.6 ; retract # # So something's still missing from the explanation. # The PostProcessingPlugin is released under the terms of the AGPLv3 or higher. print("here") import re #To perform the search and replace. import json from ..Script import Script ## Performs a search-and-replace on all g-code. # # Due to technical limitations, the search can't cross the border between # layers. class fixtempcommands(Script): def getSettingDataString(self): return json.dumps({ "name": "Add T# to certain temperature commands", "key": "FixTempCommands", "metadata": {}, "version": 2, "settings": {}, }) def execute(self, data): tool = "T0" tool_regex = re.compile(r"^T[01]$") search_string = r"^(M10[49]) S" search_regex = re.compile(search_string) replace_string = r"\1 T0 S" for layer_number, layer in enumerate(data): lines = layer.split("\n") result = [] result_append = result.append for line in lines: match = tool_regex.match(line) if match: tool = match.group(0) replace_string = r"\1 " + tool + " S" line = re.sub(search_regex, replace_string, line) result_append(line) data[layer_number] = "\n".join(result) return data