UsePreviousProbeMeasurements.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Cura PostProcessingPlugin
  2. # Author: Amanda de Castilho
  3. # Date: January 5,2019
  4. # Description: This plugin overrides probing command and inserts code to ensure
  5. # previous probe measurements are loaded and bed leveling enabled
  6. # (searches for G29 and replaces it with M501 & M420 S1)
  7. # *** Assumes G29 is in the start code, will do nothing if it isn't ***
  8. from ..Script import Script
  9. class UsePreviousProbeMeasurements(Script):
  10. def __init__(self):
  11. super().__init__()
  12. def getSettingDataString(self):
  13. return """{
  14. "name": "Use Previous Probe Measurements",
  15. "key": "UsePreviousProbeMeasurements",
  16. "metadata": {},
  17. "version": 2,
  18. "settings":
  19. {
  20. "use_previous_measurements":
  21. {
  22. "label": "Use last measurement?",
  23. "description": "Selecting this will remove the G29 probing command and instead ensure previous measurements are loaded and enabled",
  24. "type": "bool",
  25. "default_value": false
  26. }
  27. }
  28. }"""
  29. def execute(self, data):
  30. text = "M501 ;load bed level data\nM420 S1 ;enable bed leveling"
  31. if self.getSettingValueByKey("use_previous_measurements"):
  32. for layer in data:
  33. layer_index = data.index(layer)
  34. lines = layer.split("\n")
  35. for line in lines:
  36. if line.startswith("G29"):
  37. line_index = lines.index(line)
  38. lines[line_index] = text
  39. final_lines = "\n".join(lines)
  40. data[layer_index] = final_lines
  41. return data