Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ Modifica temperatura GCODE para una impresora 3d"""
- import re
- import sys
- def modify_temperatures(input_file, output_file, new_bed_temp, new_hotend_temp):
- bed_pattern = re.compile(r'(M140 S|M190 S)(\d+)')
- hotend_pattern = re.compile(r'(M104 S|M109 S)(\d+)')
- with open(input_file, 'r') as infile, open(output_file, 'w') as outfile:
- for line in infile:
- # Ignorar líneas de comentario
- if line.strip().startswith(';'):
- outfile.write(line)
- continue
- # Modificar temperatura del bed
- line = bed_pattern.sub(f'\\g<1>{new_bed_temp}', line)
- # Modificar temperatura del hot end
- line = hotend_pattern.sub(f'\\g<1>{new_hotend_temp}', line)
- outfile.write(line)
- print(f"Archivo modificado guardado como {output_file}")
- if __name__ == '__main__':
- if len(sys.argv) < 3:
- print("Error params , use. ", sys.argv[0] , "name_file new_bed_temp new_hotend_temp" )
- sys.exit(1)
- else:
- for arg in sys.argv[1:]:
- print(arg)
- input_file = sys.argv[1] # 'input.gcode'
- output_file = sys.argv[1]
- output_file =output_file.replace (".gcode","")
- output_file = output_file+"2"+".gcode"
- new_bed_temp =sys.argv[2] # Nueva temperatura para el bed
- new_hotend_temp = sys.argv[3] # Nueva temperatura para el hot end
- print ("New t. bed : ",new_bed_temp, " New t. hotend:" ,new_hotend_temp , "New File Name : ",output_file)
- modify_temperatures(input_file, output_file, new_bed_temp, new_hotend_temp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement