Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/env python
  2. import sys
  3. pwr = 1
  4. iterations = 100
  5. speed = 3000
  6. def file_bounding_box(f):
  7. x_min = None
  8. x_max = None
  9. y_min = None
  10. y_max = None
  11. mode_g1 = False
  12. for line in f:
  13. if line.startswith("G1"):
  14. mode_g1 = True
  15. elif line.startswith("G0"):
  16. mode_g1 = False
  17. if mode_g1:
  18. x_pos = line.find("X")
  19. if x_pos > -1:
  20. x_str = line[x_pos + 1:]
  21. x_num = float(x_str.split()[0])
  22. #print("found x: " + str(x_num))
  23. if (x_min == None) or (x_num < x_min):
  24. x_min = x_num
  25. if (x_max == None) or (x_num > x_max):
  26. x_max = x_num
  27. y_pos = line.find("Y")
  28. if y_pos > -1:
  29. y_str = line[y_pos + 1:]
  30. y_num = float(y_str.split()[0])
  31. #print("found y: " + str(y_num))
  32. if (y_min == None) or (y_num < y_min):
  33. y_min = y_num
  34. if (y_max == None) or (y_num > y_max):
  35. y_max = y_num
  36. return ( x_min, x_max, y_min, y_max )
  37. def write_outline(f, bb):
  38. def write(s):
  39. #print(s)
  40. f.write(s + "\n")
  41. x_min, x_max, y_min, y_max = bb
  42. print("x_min: " + str(x_min))
  43. print("x_max: " + str(x_max))
  44. print("y_min: " + str(y_min))
  45. print("y_max: " + str(y_max))
  46. pos = [
  47. ( x_min, y_min ),
  48. ( x_max, y_min ),
  49. ( x_max, y_max ),
  50. ( x_min, y_max ),
  51. ]
  52. # header
  53. write("G90")
  54. write("G28")
  55. write("G92 X0 Y-20")
  56. write("M3 I")
  57. write("M3 S0")
  58. write("G0 X0 Y0 S0 F" + str(speed))
  59. write("G1 X1 Y0 S1 F" + str(speed))
  60. write("G0 X0 Y0 S0 F" + str(speed))
  61. write("G1 X0 Y1 S1 F" + str(speed))
  62. write("G0 X0 Y0 S0 F" + str(speed))
  63. write("G0 X" + str(x_min) + " Y" + str(y_min) + " S0 F" + str(speed))
  64. for i in range(0, iterations):
  65. for x, y in pos:
  66. write("G1 X" + str(x) + " Y" + str(y) + " S" + str(pwr) + " F" + str(speed))
  67. write("M5")
  68. write("G0 X" + str(x_min) + " Y" + str(y_min) + " S0 F" + str(speed))
  69. def main():
  70. if len(sys.argv) < 3:
  71. print("Usage:")
  72. print(" " + sys.argv[0] + " input.nc output.gcode")
  73. sys.exit(1)
  74. in_file = sys.argv[1]
  75. out_file = sys.argv[2]
  76. with open(in_file, 'r') as f:
  77. bb = file_bounding_box(f)
  78. with open(out_file, 'w') as f:
  79. write_outline(f, bb)
  80. if __name__ == '__main__':
  81. main()