DisplayFilenameAndLayerOnLCD.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Cura PostProcessingPlugin
  2. # Author: Amanda de Castilho
  3. # Date: August 28, 2018
  4. # Description: This plugin inserts a line at the start of each layer,
  5. # M117 - displays the filename and layer height to the LCD
  6. # Alternatively, user can override the filename to display alt text + layer height
  7. from ..Script import Script
  8. from UM.Application import Application
  9. class DisplayFilenameAndLayerOnLCD(Script):
  10. def __init__(self):
  11. super().__init__()
  12. def getSettingDataString(self):
  13. return """{
  14. "name": "Display filename and layer on LCD",
  15. "key": "DisplayFilenameAndLayerOnLCD",
  16. "metadata": {},
  17. "version": 2,
  18. "settings":
  19. {
  20. "name":
  21. {
  22. "label": "text to display:",
  23. "description": "By default the current filename will be displayed on the LCD. Enter text here to override the filename and display something else.",
  24. "type": "str",
  25. "default_value": ""
  26. }
  27. }
  28. }"""
  29. def execute(self, data):
  30. if self.getSettingValueByKey("name") != "":
  31. name = self.getSettingValueByKey("name")
  32. else:
  33. name = Application.getInstance().getPrintInformation().jobName
  34. lcd_text = "M117 " + name + " layer: "
  35. i = 0
  36. for layer in data:
  37. display_text = lcd_text + str(i)
  38. layer_index = data.index(layer)
  39. lines = layer.split("\n")
  40. for line in lines:
  41. if line.startswith(";LAYER:"):
  42. line_index = lines.index(line)
  43. lines.insert(line_index + 1, display_text)
  44. i += 1
  45. final_lines = "\n".join(lines)
  46. data[layer_index] = final_lines
  47. return data