PauseAtHeightforRepetier.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. from ..Script import Script
  2. class PauseAtHeightforRepetier(Script):
  3. def __init__(self):
  4. super().__init__()
  5. def getSettingDataString(self):
  6. return """{
  7. "name":"Pause at height for repetier",
  8. "key": "PauseAtHeightforRepetier",
  9. "metadata": {},
  10. "version": 2,
  11. "settings":
  12. {
  13. "pause_height":
  14. {
  15. "label": "Pause height",
  16. "description": "At what height should the pause occur",
  17. "unit": "mm",
  18. "type": "float",
  19. "default_value": 5.0
  20. },
  21. "head_park_x":
  22. {
  23. "label": "Park print head X",
  24. "description": "What x location does the head move to when pausing.",
  25. "unit": "mm",
  26. "type": "float",
  27. "default_value": 5.0
  28. },
  29. "head_park_y":
  30. {
  31. "label": "Park print head Y",
  32. "description": "What y location does the head move to when pausing.",
  33. "unit": "mm",
  34. "type": "float",
  35. "default_value": 5.0
  36. },
  37. "head_move_Z":
  38. {
  39. "label": "Head move Z",
  40. "description": "The Hieght of Z-axis retraction before parking.",
  41. "unit": "mm",
  42. "type": "float",
  43. "default_value": 15.0
  44. },
  45. "retraction_amount":
  46. {
  47. "label": "Retraction",
  48. "description": "How much fillament must be retracted at pause.",
  49. "unit": "mm",
  50. "type": "float",
  51. "default_value": 5.0
  52. },
  53. "extrude_amount":
  54. {
  55. "label": "Extrude amount",
  56. "description": "How much filament should be extruded after pause. This is needed when doing a material change on Ultimaker2's to compensate for the retraction after the change. In that case 128+ is recommended.",
  57. "unit": "mm",
  58. "type": "float",
  59. "default_value": 90.0
  60. },
  61. "redo_layers":
  62. {
  63. "label": "Redo layers",
  64. "description": "Redo a number of previous layers after a pause to increases adhesion.",
  65. "unit": "layers",
  66. "type": "int",
  67. "default_value": 0
  68. }
  69. }
  70. }"""
  71. def execute(self, data):
  72. x = 0.
  73. y = 0.
  74. current_z = 0.
  75. pause_z = self.getSettingValueByKey("pause_height")
  76. retraction_amount = self.getSettingValueByKey("retraction_amount")
  77. extrude_amount = self.getSettingValueByKey("extrude_amount")
  78. park_x = self.getSettingValueByKey("head_park_x")
  79. park_y = self.getSettingValueByKey("head_park_y")
  80. move_Z = self.getSettingValueByKey("head_move_Z")
  81. layers_started = False
  82. redo_layers = self.getSettingValueByKey("redo_layers")
  83. for layer in data:
  84. lines = layer.split("\n")
  85. for line in lines:
  86. if ";LAYER:0" in line:
  87. layers_started = True
  88. continue
  89. if not layers_started:
  90. continue
  91. if self.getValue(line, 'G') == 1 or self.getValue(line, 'G') == 0:
  92. current_z = self.getValue(line, 'Z')
  93. x = self.getValue(line, 'X', x)
  94. y = self.getValue(line, 'Y', y)
  95. if current_z != None:
  96. if current_z >= pause_z:
  97. index = data.index(layer)
  98. prevLayer = data[index-1]
  99. prevLines = prevLayer.split("\n")
  100. current_e = 0.
  101. for prevLine in reversed(prevLines):
  102. current_e = self.getValue(prevLine, 'E', -1)
  103. if current_e >= 0:
  104. break
  105. prepend_gcode = ";TYPE:CUSTOM\n"
  106. prepend_gcode += ";added code by post processing\n"
  107. prepend_gcode += ";script: PauseAtHeightforRepetier.py\n"
  108. prepend_gcode += ";current z: %f \n" % (current_z)
  109. prepend_gcode += ";current X: %f \n" % (x)
  110. prepend_gcode += ";current Y: %f \n" % (y)
  111. #Retraction
  112. prepend_gcode += "M83\n"
  113. if retraction_amount != 0:
  114. prepend_gcode += "G1 E-%f F6000\n" % (retraction_amount)
  115. #Move the head away
  116. prepend_gcode += "G1 Z%f F300\n" % (1 + current_z)
  117. prepend_gcode += "G1 X%f Y%f F9000\n" % (park_x, park_y)
  118. if current_z < move_Z:
  119. prepend_gcode += "G1 Z%f F300\n" % (current_z + move_Z)
  120. #Disable the E steppers
  121. prepend_gcode += "M84 E0\n"
  122. #Wait till the user continues printing
  123. prepend_gcode += "@pause now change filament and press continue printing ;Do the actual pause\n"
  124. #Push the filament back,
  125. if retraction_amount != 0:
  126. prepend_gcode += "G1 E%f F6000\n" % (retraction_amount)
  127. # Optionally extrude material
  128. if extrude_amount != 0:
  129. prepend_gcode += "G1 E%f F200\n" % (extrude_amount)
  130. prepend_gcode += "@info wait for cleaning nozzle from previous filament\n"
  131. prepend_gcode += "@pause remove the waste filament from parking area and press continue printing\n"
  132. # and retract again, the properly primes the nozzle when changing filament.
  133. if retraction_amount != 0:
  134. prepend_gcode += "G1 E-%f F6000\n" % (retraction_amount)
  135. #Move the head back
  136. prepend_gcode += "G1 Z%f F300\n" % (1 + current_z)
  137. prepend_gcode +="G1 X%f Y%f F9000\n" % (x, y)
  138. if retraction_amount != 0:
  139. prepend_gcode +="G1 E%f F6000\n" % (retraction_amount)
  140. prepend_gcode +="G1 F9000\n"
  141. prepend_gcode +="M82\n"
  142. # reset extrude value to pre pause value
  143. prepend_gcode +="G92 E%f\n" % (current_e)
  144. layer = prepend_gcode + layer
  145. # include a number of previous layers
  146. for i in range(1, redo_layers + 1):
  147. prevLayer = data[index-i]
  148. layer = prevLayer + layer
  149. data[index] = layer #Override the data of this layer with the modified data
  150. return data
  151. break
  152. return data