Closed benoitsahli closed 1 year ago
I don't think we want to expose this in the configuration because of this one use case, not to mention that it would require more changes than it probably looks. If you want to use the preview, you can do the substitution using an external script, which would be run after processing the G-code preview.
An example python script for inspiration (without any guarantees):
import sys
import re
def replace_e_with_u_in_file(filename):
try:
# Read the content of the input file in binary mode
with open(filename, 'rb') as file:
lines = file.readlines()
# Define the regex pattern
pattern = r"^(G1.*)(E)"
replacement = r"\1U"
# Apply the substitution to each line
modified_lines = [re.sub(pattern, replacement, line.decode()) if line.decode().startswith("G1") else line.decode() for line in lines]
# Write the modified content back to the file in binary mode
with open(filename, 'wb') as file:
file.writelines(line.encode() for line in modified_lines)
print(f"Substitution completed successfully in {filename}")
except FileNotFoundError:
print(f"File not found: {filename}")
except Exception as e:
print(f"An error occurred: {str(e)}")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python replace_e_with_u.py <filename>")
else:
filename = sys.argv[1]
replace_e_with_u_in_file(filename)
Closing.
Is your feature request related to a problem? Please describe. Actually, the software use the axis letter “E” for the extruder. We use a Beckhoff TwinCAT CNC system and the axis letter are XYZ ABC UVW. Our system does not accept “E” as axis name (see picture) In the Slicer, when we add the g-code substitution "E" shall be replaced by "U", then the gcode preview is not working anymore.
Describe the solution you'd like Can you add a setting in PrusaSlicer to change the extruder letter ? That would be great.