PauseAtHeight.py 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. # Copyright (c) 2023 UltiMaker
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. # Revised by GregValiant 10-17-2022
  4. # Changed "extrude" line to before the nozzle moves back to the print (if not Repetier or Griffin).
  5. # Add M104 option for Resume temperature
  6. from ..Script import Script
  7. import re
  8. from UM.Application import Application #To get the current printer's settings.
  9. from UM.Logger import Logger
  10. from typing import List, Tuple
  11. class PauseAtHeight(Script):
  12. def __init__(self) -> None:
  13. super().__init__()
  14. def getSettingDataString(self) -> str:
  15. return """{
  16. "name": "Pause at height",
  17. "key": "PauseAtHeight",
  18. "metadata": {},
  19. "version": 2,
  20. "settings":
  21. {
  22. "pause_at":
  23. {
  24. "label": "Pause at",
  25. "description": "Whether to pause at a certain height or at a certain layer.",
  26. "type": "enum",
  27. "options": {"height": "Height", "layer_no": "Layer Number"},
  28. "default_value": "layer_no"
  29. },
  30. "pause_height":
  31. {
  32. "label": "Pause Height",
  33. "description": "At what height should the pause occur?",
  34. "unit": "mm",
  35. "type": "float",
  36. "default_value": 5.0,
  37. "minimum_value": "0",
  38. "minimum_value_warning": "0.27",
  39. "enabled": "pause_at == 'height'"
  40. },
  41. "pause_layer":
  42. {
  43. "label": "Pause Layer",
  44. "description": "Enter the Number of the LAST layer you want to finish prior to the pause. Note that 0 is the first layer printed.",
  45. "type": "int",
  46. "value": "math.floor((pause_height - 0.27) / 0.1) + 1",
  47. "minimum_value": "0",
  48. "minimum_value_warning": "1",
  49. "enabled": "pause_at == 'layer_no'"
  50. },
  51. "pause_method":
  52. {
  53. "label": "Method",
  54. "description": "The method or gcode command to use for pausing.",
  55. "type": "enum",
  56. "options": {"marlin": "Marlin (M0)", "griffin": "Griffin (M0, firmware retract)", "bq": "BQ (M25)", "reprap": "RepRap (M226)", "repetier": "Repetier/OctoPrint (@pause)"},
  57. "default_value": "marlin",
  58. "value": "\\\"griffin\\\" if machine_gcode_flavor==\\\"Griffin\\\" else \\\"reprap\\\" if machine_gcode_flavor==\\\"RepRap (RepRap)\\\" else \\\"repetier\\\" if machine_gcode_flavor==\\\"Repetier\\\" else \\\"bq\\\" if \\\"BQ\\\" in machine_name or \\\"Flying Bear Ghost 4S\\\" in machine_name else \\\"marlin\\\""
  59. },
  60. "hold_steppers_on":
  61. {
  62. "label": "Keep motors engaged",
  63. "description": "Keep the steppers engaged to allow change of filament without moving the head. Applying too much force will move the head/bed anyway",
  64. "type": "bool",
  65. "default_value": false,
  66. "enabled": "pause_method != \\\"griffin\\\""
  67. },
  68. "disarm_timeout":
  69. {
  70. "label": "Disarm timeout",
  71. "description": "After this time steppers are going to disarm (meaning that they can easily lose their positions). Set this to 0 if you don't want to set any duration and disarm immediately.",
  72. "type": "int",
  73. "value": "0",
  74. "minimum_value": "0",
  75. "minimum_value_warning": "0",
  76. "maximum_value_warning": "1800",
  77. "unit": "s",
  78. "enabled": "not hold_steppers_on"
  79. },
  80. "head_park_enabled":
  81. {
  82. "label": "Park Print",
  83. "description": "Instruct the head to move to a safe location when pausing. Leave this unchecked if your printer handles parking for you.",
  84. "type": "bool",
  85. "default_value": true,
  86. "enabled": "pause_method != \\\"griffin\\\""
  87. },
  88. "head_park_x":
  89. {
  90. "label": "Park Print Head X",
  91. "description": "What X location does the head move to when pausing.",
  92. "unit": "mm",
  93. "type": "float",
  94. "default_value": 190,
  95. "enabled": "head_park_enabled and pause_method != \\\"griffin\\\""
  96. },
  97. "head_park_y":
  98. {
  99. "label": "Park Print Head Y",
  100. "description": "What Y location does the head move to when pausing.",
  101. "unit": "mm",
  102. "type": "float",
  103. "default_value": 190,
  104. "enabled": "head_park_enabled and pause_method != \\\"griffin\\\""
  105. },
  106. "head_move_z":
  107. {
  108. "label": "Head move Z",
  109. "description": "The Height of Z-axis retraction before parking.",
  110. "unit": "mm",
  111. "type": "float",
  112. "default_value": 15.0,
  113. "enabled": "head_park_enabled and pause_method == \\\"repetier\\\""
  114. },
  115. "retraction_amount":
  116. {
  117. "label": "Retraction",
  118. "description": "How much filament must be retracted at pause.",
  119. "unit": "mm",
  120. "type": "float",
  121. "default_value": 0,
  122. "enabled": "pause_method != \\\"griffin\\\""
  123. },
  124. "retraction_speed":
  125. {
  126. "label": "Retraction Speed",
  127. "description": "How fast to retract the filament.",
  128. "unit": "mm/s",
  129. "type": "float",
  130. "default_value": 25,
  131. "enabled": "pause_method not in [\\\"griffin\\\", \\\"repetier\\\"]"
  132. },
  133. "extrude_amount":
  134. {
  135. "label": "Extrude Amount",
  136. "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.",
  137. "unit": "mm",
  138. "type": "float",
  139. "default_value": 0,
  140. "enabled": "pause_method != \\\"griffin\\\""
  141. },
  142. "extrude_speed":
  143. {
  144. "label": "Extrude Speed",
  145. "description": "How fast to extrude the material after pause.",
  146. "unit": "mm/s",
  147. "type": "float",
  148. "default_value": 3.3333,
  149. "enabled": "pause_method not in [\\\"griffin\\\", \\\"repetier\\\"]"
  150. },
  151. "redo_layer":
  152. {
  153. "label": "Redo Layer",
  154. "description": "Redo the last layer before the pause, to get the filament flowing again after having oozed a bit during the pause.",
  155. "type": "bool",
  156. "default_value": false
  157. },
  158. "standby_wait_for_temperature_enabled":
  159. {
  160. "label": "Use M109 for standby temperature? (M104 when false)",
  161. "description": "Wait for hot end after Resume? (If your standby temperature is lower than the Printing temperature CHECK and use M109",
  162. "type": "bool",
  163. "default_value": true,
  164. "enabled": "pause_method not in [\\\"griffin\\\", \\\"repetier\\\"]"
  165. },
  166. "standby_temperature":
  167. {
  168. "label": "Standby Temperature",
  169. "description": "Change the temperature during the pause.",
  170. "unit": "°C",
  171. "type": "int",
  172. "default_value": 0,
  173. "enabled": "pause_method not in [\\\"griffin\\\", \\\"repetier\\\"]"
  174. },
  175. "display_text":
  176. {
  177. "label": "Display Text",
  178. "description": "Text that should appear on the display while paused. If left empty, there will not be any message.",
  179. "type": "str",
  180. "default_value": "",
  181. "enabled": "pause_method != \\\"repetier\\\""
  182. },
  183. "machine_name":
  184. {
  185. "label": "Machine Type",
  186. "description": "The name of your 3D printer model. This setting is controlled by the script and will not be visible.",
  187. "default_value": "Unknown",
  188. "type": "str",
  189. "enabled": false
  190. },
  191. "machine_gcode_flavor":
  192. {
  193. "label": "G-code flavor",
  194. "description": "The type of g-code to be generated. This setting is controlled by the script and will not be visible.",
  195. "type": "enum",
  196. "options":
  197. {
  198. "RepRap (Marlin/Sprinter)": "Marlin",
  199. "RepRap (Volumetric)": "Marlin (Volumetric)",
  200. "RepRap (RepRap)": "RepRap",
  201. "UltiGCode": "Ultimaker 2",
  202. "Griffin": "Griffin",
  203. "Makerbot": "Makerbot",
  204. "BFB": "Bits from Bytes",
  205. "MACH3": "Mach3",
  206. "Repetier": "Repetier"
  207. },
  208. "default_value": "RepRap (Marlin/Sprinter)",
  209. "enabled": false
  210. },
  211. "beep_at_pause":
  212. {
  213. "label": "Beep at pause",
  214. "description": "Make a beep when pausing",
  215. "type": "bool",
  216. "default_value": false
  217. },
  218. "beep_length":
  219. {
  220. "label": "Beep length",
  221. "description": "How much should the beep last",
  222. "type": "int",
  223. "default_value": "1000",
  224. "unit": "ms",
  225. "enabled": "beep_at_pause"
  226. },
  227. "custom_gcode_before_pause":
  228. {
  229. "label": "G-code Before Pause",
  230. "description": "Custom g-code to run before the pause. EX: M300 to beep. Use a comma to separate multiple commands. EX: M400,M300,M117 Pause",
  231. "type": "str",
  232. "default_value": ""
  233. },
  234. "custom_gcode_after_pause":
  235. {
  236. "label": "G-code After Pause",
  237. "description": "Custom g-code to run after the pause. Use a comma to separate multiple commands. EX: M204 X8 Y8,M106 S0,M117 Resume",
  238. "type": "str",
  239. "default_value": ""
  240. }
  241. }
  242. }"""
  243. ## Copy machine name and gcode flavor from global stack so we can use their value in the script stack
  244. def initialize(self) -> None:
  245. super().initialize()
  246. global_container_stack = Application.getInstance().getGlobalContainerStack()
  247. if global_container_stack is None or self._instance is None:
  248. return
  249. for key in ["machine_name", "machine_gcode_flavor"]:
  250. self._instance.setProperty(key, "value", global_container_stack.getProperty(key, "value"))
  251. ## Get the X and Y values for a layer (will be used to get X and Y of the
  252. # layer after the pause).
  253. def getNextXY(self, layer: str) -> Tuple[float, float]:
  254. """Get the X and Y values for a layer (will be used to get X and Y of the layer after the pause)."""
  255. lines = layer.split("\n")
  256. for line in lines:
  257. if line.startswith(("G0", "G1", "G2", "G3")):
  258. if self.getValue(line, "X") is not None and self.getValue(line, "Y") is not None:
  259. x = self.getValue(line, "X")
  260. y = self.getValue(line, "Y")
  261. return x, y
  262. return 0, 0
  263. def execute(self, data: List[str]) -> List[str]:
  264. """Inserts the pause commands.
  265. :param data: List of layers.
  266. :return: New list of layers.
  267. """
  268. pause_at = self.getSettingValueByKey("pause_at")
  269. pause_height = self.getSettingValueByKey("pause_height")
  270. pause_layer = self.getSettingValueByKey("pause_layer")
  271. hold_steppers_on = self.getSettingValueByKey("hold_steppers_on")
  272. disarm_timeout = self.getSettingValueByKey("disarm_timeout")
  273. retraction_amount = self.getSettingValueByKey("retraction_amount")
  274. retraction_speed = self.getSettingValueByKey("retraction_speed")
  275. extrude_amount = self.getSettingValueByKey("extrude_amount")
  276. extrude_speed = self.getSettingValueByKey("extrude_speed")
  277. park_enabled = self.getSettingValueByKey("head_park_enabled")
  278. park_x = self.getSettingValueByKey("head_park_x")
  279. park_y = self.getSettingValueByKey("head_park_y")
  280. move_z = self.getSettingValueByKey("head_move_z")
  281. layers_started = False
  282. redo_layer = self.getSettingValueByKey("redo_layer")
  283. standby_wait_for_temperature_enabled = self.getSettingValueByKey("standby_wait_for_temperature_enabled")
  284. standby_temperature = self.getSettingValueByKey("standby_temperature")
  285. firmware_retract = Application.getInstance().getGlobalContainerStack().getProperty("machine_firmware_retract", "value")
  286. control_temperatures = Application.getInstance().getGlobalContainerStack().getProperty("machine_nozzle_temp_enabled", "value")
  287. initial_layer_height = Application.getInstance().getGlobalContainerStack().getProperty("layer_height_0", "value")
  288. display_text = self.getSettingValueByKey("display_text")
  289. gcode_before = re.sub("\\s*,\\s*", "\n", self.getSettingValueByKey("custom_gcode_before_pause"))
  290. gcode_after = re.sub("\\s*,\\s*", "\n", self.getSettingValueByKey("custom_gcode_after_pause"))
  291. beep_at_pause = self.getSettingValueByKey("beep_at_pause")
  292. beep_length = self.getSettingValueByKey("beep_length")
  293. pause_method = self.getSettingValueByKey("pause_method")
  294. pause_command = {
  295. "marlin": self.putValue(M = 0),
  296. "griffin": self.putValue(M = 0),
  297. "bq": self.putValue(M = 25),
  298. "reprap": self.putValue(M = 226),
  299. "repetier": self.putValue("@pause now change filament and press continue printing")
  300. }[pause_method]
  301. # T = ExtruderManager.getInstance().getActiveExtruderStack().getProperty("material_print_temperature", "value")
  302. # use offset to calculate the current height: <current_height> = <current_z> - <layer_0_z>
  303. layer_0_z = 0
  304. current_z = 0
  305. current_height = 0
  306. current_layer = 0
  307. current_extrusion_f = 0
  308. got_first_g_cmd_on_layer_0 = False
  309. current_t = 0 #Tracks the current extruder for tracking the target temperature.
  310. target_temperature = {} #Tracks the current target temperature for each extruder.
  311. nbr_negative_layers = 0
  312. for index, layer in enumerate(data):
  313. lines = layer.split("\n")
  314. # Scroll each line of instruction for each layer in the G-code
  315. for line in lines:
  316. # Fist positive layer reached
  317. if ";LAYER:0" in line:
  318. layers_started = True
  319. # Count nbr of negative layers (raft)
  320. elif ";LAYER:-" in line:
  321. nbr_negative_layers += 1
  322. #Track the latest printing temperature in order to resume at the correct temperature.
  323. if re.match("T(\d*)", line):
  324. current_t = self.getValue(line, "T")
  325. m = self.getValue(line, "M")
  326. if m is not None and (m == 104 or m == 109) and self.getValue(line, "S") is not None:
  327. extruder = current_t
  328. if self.getValue(line, "T") is not None:
  329. extruder = self.getValue(line, "T")
  330. target_temperature[extruder] = self.getValue(line, "S")
  331. if not layers_started:
  332. continue
  333. # Look for the feed rate of an extrusion instruction
  334. if self.getValue(line, "F") is not None and self.getValue(line, "E") is not None:
  335. current_extrusion_f = self.getValue(line, "F")
  336. # If a Z instruction is in the line, read the current Z
  337. if self.getValue(line, "Z") is not None:
  338. current_z = self.getValue(line, "Z")
  339. if pause_at == "height":
  340. # Ignore if the line is not G1 or G0
  341. if self.getValue(line, "G") != 1 and self.getValue(line, "G") != 0:
  342. continue
  343. # This block is executed once, the first time there is a G
  344. # command, to get the z offset (z for first positive layer)
  345. if not got_first_g_cmd_on_layer_0:
  346. layer_0_z = current_z - initial_layer_height
  347. got_first_g_cmd_on_layer_0 = True
  348. current_height = current_z - layer_0_z
  349. if current_height < pause_height:
  350. continue # Scan the entire layer, z-changes are not always on the same/first line.
  351. # Pause at layer
  352. else:
  353. if not line.startswith(";LAYER:"):
  354. continue
  355. current_layer = line[len(";LAYER:"):]
  356. try:
  357. current_layer = int(current_layer)
  358. # Couldn't cast to int. Something is wrong with this
  359. # g-code data
  360. except ValueError:
  361. continue
  362. if current_layer < pause_layer - nbr_negative_layers:
  363. continue
  364. prev_layer = data[index - 1]
  365. prev_lines = prev_layer.split("\n")
  366. current_e = 0.
  367. # Access last layer, browse it backwards to find
  368. # last extruder absolute position
  369. for prevLine in reversed(prev_lines):
  370. current_e = self.getValue(prevLine, "E", -1)
  371. if current_e >= 0:
  372. break
  373. # and also find last X,Y
  374. for prevLine in reversed(prev_lines):
  375. if prevLine.startswith(("G0", "G1", "G2", "G3")):
  376. if self.getValue(prevLine, "X") is not None and self.getValue(prevLine, "Y") is not None:
  377. x = self.getValue(prevLine, "X")
  378. y = self.getValue(prevLine, "Y")
  379. break
  380. # Maybe redo the last layer.
  381. if redo_layer:
  382. prev_layer = data[index - 1]
  383. layer = prev_layer + layer
  384. # Get extruder's absolute position at the
  385. # beginning of the redone layer.
  386. # see https://github.com/nallath/PostProcessingPlugin/issues/55
  387. # Get X and Y from the next layer (better position for
  388. # the nozzle)
  389. x, y = self.getNextXY(layer)
  390. prev_lines = prev_layer.split("\n")
  391. for lin in prev_lines:
  392. new_e = self.getValue(lin, "E", current_e)
  393. if new_e != current_e:
  394. current_e = new_e
  395. break
  396. prepend_gcode = ";TYPE:CUSTOM\n"
  397. prepend_gcode += ";added code by post processing\n"
  398. prepend_gcode += ";script: PauseAtHeight.py\n"
  399. if pause_at == "height":
  400. prepend_gcode += ";current z: {z}\n".format(z = current_z)
  401. prepend_gcode += ";current height: {height}\n".format(height = current_height)
  402. else:
  403. prepend_gcode += ";current layer: {layer}\n".format(layer = current_layer)
  404. if pause_method == "repetier":
  405. #Retraction
  406. prepend_gcode += self.putValue(M = 83) + " ; switch to relative E values for any needed retraction\n"
  407. if retraction_amount != 0:
  408. prepend_gcode += self.putValue(G = 1, E = -retraction_amount, F = 6000) + "\n"
  409. if park_enabled:
  410. #Move the head away
  411. prepend_gcode += self.putValue(G = 1, Z = current_z + 1, F = 300) + " ; move up a millimeter to get out of the way\n"
  412. prepend_gcode += self.putValue(G = 1, X = park_x, Y = park_y, F = 9000) + "\n"
  413. if current_z < move_z:
  414. prepend_gcode += self.putValue(G = 1, Z = current_z + move_z, F = 300) + "\n"
  415. #Disable the E steppers
  416. prepend_gcode += self.putValue(M = 84, E = 0) + "\n"
  417. elif pause_method != "griffin":
  418. # Retraction
  419. prepend_gcode += self.putValue(M = 83) + " ; switch to relative E values for any needed retraction\n"
  420. if retraction_amount != 0:
  421. if firmware_retract: #Can't set the distance directly to what the user wants. We have to choose ourselves.
  422. retraction_count = 1 if control_temperatures else 3 #Retract more if we don't control the temperature.
  423. for i in range(retraction_count):
  424. prepend_gcode += self.putValue(G = 10) + "\n"
  425. else:
  426. prepend_gcode += self.putValue(G = 1, E = -retraction_amount, F = retraction_speed * 60) + "\n"
  427. if park_enabled:
  428. # Move the head away
  429. prepend_gcode += self.putValue(G = 1, Z = current_z + 1, F = 300) + " ; move up a millimeter to get out of the way\n"
  430. # This line should be ok
  431. prepend_gcode += self.putValue(G = 1, X = park_x, Y = park_y, F = 9000) + "\n"
  432. if current_z < 15:
  433. prepend_gcode += self.putValue(G = 1, Z = 15, F = 300) + " ; too close to bed--move to at least 15mm\n"
  434. if control_temperatures:
  435. # Set extruder standby temperature
  436. prepend_gcode += self.putValue(M = 104, S = standby_temperature) + " ; standby temperature\n"
  437. if display_text:
  438. prepend_gcode += "M117 " + display_text + "\n"
  439. # Set the disarm timeout
  440. if pause_method != "griffin":
  441. if hold_steppers_on:
  442. prepend_gcode += self.putValue(M = 84, S = 3600) + " ; Keep steppers engaged for 1h\n"
  443. elif disarm_timeout > 0:
  444. prepend_gcode += self.putValue(M = 84, S = disarm_timeout) + " ; Set the disarm timeout\n"
  445. # Beep at pause
  446. if beep_at_pause:
  447. prepend_gcode += self.putValue(M = 300, S = 440, P = beep_length) + " ; Beep\n"
  448. # Set a custom GCODE section before pause
  449. if gcode_before:
  450. prepend_gcode += gcode_before + "\n"
  451. # Wait till the user continues printing
  452. prepend_gcode += pause_command + " ; Do the actual pause\n"
  453. # Set a custom GCODE section after pause
  454. if gcode_after:
  455. prepend_gcode += gcode_after + "\n"
  456. if pause_method == "repetier":
  457. #Push the filament back,
  458. if retraction_amount != 0:
  459. prepend_gcode += self.putValue(G = 1, E = retraction_amount, F = 6000) + "\n"
  460. # Optionally extrude material
  461. if extrude_amount != 0:
  462. prepend_gcode += self.putValue(G = 1, E = extrude_amount, F = 200) + "; Extra extrude after the unpause\n"
  463. prepend_gcode += self.putValue("@info wait for cleaning nozzle from previous filament") + "\n"
  464. prepend_gcode += self.putValue("@pause remove the waste filament from parking area and press continue printing") + "\n"
  465. # and retract again, the properly primes the nozzle when changing filament.
  466. if retraction_amount != 0:
  467. prepend_gcode += self.putValue(G = 1, E = -retraction_amount, F = 6000) + "\n"
  468. #Move the head back
  469. if park_enabled:
  470. prepend_gcode += self.putValue(G = 1, X = x, Y = y, F = 9000) + "\n"
  471. prepend_gcode += self.putValue(G = 1, Z = current_z, F = 300) + "\n"
  472. if retraction_amount != 0:
  473. prepend_gcode += self.putValue(G = 1, E = retraction_amount, F = 6000) + "\n"
  474. if current_extrusion_f != 0:
  475. prepend_gcode += self.putValue(G = 1, F = current_extrusion_f) + " ; restore extrusion feedrate\n"
  476. else:
  477. Logger.log("w", "No previous feedrate found in gcode, feedrate for next layer(s) might be incorrect")
  478. extrusion_mode_string = "absolute"
  479. extrusion_mode_numeric = 82
  480. relative_extrusion = Application.getInstance().getGlobalContainerStack().getProperty("relative_extrusion", "value")
  481. if relative_extrusion:
  482. extrusion_mode_string = "relative"
  483. extrusion_mode_numeric = 83
  484. prepend_gcode += self.putValue(M = extrusion_mode_numeric) + " ; switch back to " + extrusion_mode_string + " E values\n"
  485. # reset extrude value to pre pause value
  486. prepend_gcode += self.putValue(G = 92, E = current_e) + "\n"
  487. elif pause_method != "griffin":
  488. if control_temperatures:
  489. # Set extruder resume temperature
  490. if standby_wait_for_temperature_enabled:
  491. WFT_numeric = 109
  492. Temp_resume_Text = " ; WAIT for resume temperature\n"
  493. else:
  494. WFT_numeric = 104
  495. Temp_resume_Text = " ; resume temperature\n"
  496. prepend_gcode += self.putValue(M=WFT_numeric,
  497. S=int(target_temperature.get(current_t, 0))) + Temp_resume_Text
  498. if extrude_amount != 0: # Need to prime after the pause.
  499. # Push the filament back.
  500. if extrude_speed == 0:
  501. extrude_speed = 25
  502. if extrude_amount != 0:
  503. prepend_gcode += self.putValue(G=1, E=extrude_amount, F=extrude_speed * 60) + "\n"
  504. # Move the head back
  505. if park_enabled:
  506. if current_z < 15:
  507. prepend_gcode += self.putValue(G = 1, Z = current_z, F = 300) + "\n"
  508. prepend_gcode += self.putValue(G = 1, X = x, Y = y, F = 9000) + "\n"
  509. prepend_gcode += self.putValue(G = 1, Z = current_z, F = 300) + " ; move back down to resume height\n"
  510. if retraction_amount != 0:
  511. if firmware_retract: #Can't set the distance directly to what the user wants. We have to choose ourselves.
  512. retraction_count = 1 if control_temperatures else 3 #Retract more if we don't control the temperature.
  513. for i in range(retraction_count):
  514. prepend_gcode += self.putValue(G = 11) + "\n"
  515. if current_extrusion_f != 0:
  516. prepend_gcode += self.putValue(G = 1, F = current_extrusion_f) + " ; restore extrusion feedrate\n"
  517. else:
  518. Logger.log("w", "No previous feedrate found in gcode, feedrate for next layer(s) might be incorrect")
  519. extrusion_mode_string = "absolute"
  520. extrusion_mode_numeric = 82
  521. relative_extrusion = Application.getInstance().getGlobalContainerStack().getProperty("relative_extrusion", "value")
  522. if relative_extrusion:
  523. extrusion_mode_string = "relative"
  524. extrusion_mode_numeric = 83
  525. prepend_gcode += self.putValue(M = extrusion_mode_numeric) + " ; switch back to " + extrusion_mode_string + " E values\n"
  526. # reset extrude value to pre pause value
  527. prepend_gcode += self.putValue(G = 92, E = current_e) + "\n"
  528. elif redo_layer:
  529. # All other options reset the E value to what it was before the pause because E things were added.
  530. # If it's not yet reset, it still needs to be reset if there were any redo layers.
  531. prepend_gcode += self.putValue(G = 92, E = current_e) + "\n"
  532. layer = prepend_gcode + layer
  533. # Override the data of this layer with the
  534. # modified data
  535. data[index] = layer
  536. return data
  537. return data