InsertAtLayerChange.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Created by Wayne Porter
  2. from ..Script import Script
  3. class InsertAtLayerChange(Script):
  4. def __init__(self):
  5. super().__init__()
  6. def getSettingDataString(self):
  7. return """{
  8. "name": "Insert at layer change",
  9. "key": "InsertAtLayerChange",
  10. "metadata": {},
  11. "version": 2,
  12. "settings":
  13. {
  14. "insert_location":
  15. {
  16. "label": "When to insert",
  17. "description": "Whether to insert code before or after layer change.",
  18. "type": "enum",
  19. "options": {"before": "Before", "after": "After"},
  20. "default_value": "before"
  21. },
  22. "gcode_to_add":
  23. {
  24. "label": "GCODE to insert.",
  25. "description": "GCODE to add before or after layer change.",
  26. "type": "str",
  27. "default_value": ""
  28. }
  29. }
  30. }"""
  31. def execute(self, data):
  32. gcode_to_add = self.getSettingValueByKey("gcode_to_add") + "\n"
  33. for layer in data:
  34. # Check that a layer is being printed
  35. lines = layer.split("\n")
  36. for line in lines:
  37. if ";LAYER:" in line:
  38. index = data.index(layer)
  39. if self.getSettingValueByKey("insert_location") == "before":
  40. layer = gcode_to_add + layer
  41. else:
  42. layer = layer + gcode_to_add
  43. data[index] = layer
  44. break
  45. return data