Advertisement
AntonioVillanueva

Cambia temperatura bed y hotend en GCODE

Oct 7th, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. """ Modifica temperatura GCODE para una impresora 3d"""
  2. import re
  3. import sys
  4.  
  5. def modify_temperatures(input_file, output_file, new_bed_temp, new_hotend_temp):
  6.     bed_pattern = re.compile(r'(M140 S|M190 S)(\d+)')
  7.     hotend_pattern = re.compile(r'(M104 S|M109 S)(\d+)')
  8.  
  9.     with open(input_file, 'r') as infile, open(output_file, 'w') as outfile:
  10.         for line in infile:
  11.             # Ignorar líneas de comentario
  12.             if line.strip().startswith(';'):
  13.                 outfile.write(line)
  14.                 continue
  15.  
  16.             # Modificar temperatura del bed
  17.             line = bed_pattern.sub(f'\\g<1>{new_bed_temp}', line)
  18.            
  19.             # Modificar temperatura del hot end
  20.             line = hotend_pattern.sub(f'\\g<1>{new_hotend_temp}', line)
  21.            
  22.             outfile.write(line)
  23.  
  24.     print(f"Archivo modificado guardado como {output_file}")
  25.  
  26.  
  27. if __name__ == '__main__':
  28.  
  29.     if len(sys.argv) < 3:
  30.         print("Error params , use. ", sys.argv[0] , "name_file new_bed_temp new_hotend_temp" )
  31.         sys.exit(1)
  32.     else:
  33.         for arg in sys.argv[1:]:
  34.             print(arg)
  35.  
  36.     input_file = sys.argv[1] # 'input.gcode'
  37.     output_file = sys.argv[1]
  38.    
  39.     output_file =output_file.replace (".gcode","")
  40.     output_file = output_file+"2"+".gcode"
  41.    
  42.     new_bed_temp =sys.argv[2]  # Nueva temperatura para el bed
  43.     new_hotend_temp = sys.argv[3]  # Nueva temperatura para el hot end
  44.    
  45.     print ("New t. bed : ",new_bed_temp, " New t. hotend:" ,new_hotend_temp , "New File Name : ",output_file)
  46.  
  47.     modify_temperatures(input_file, output_file, new_bed_temp, new_hotend_temp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement