DisplayFilenameAndLayerOnLCD.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Cura PostProcessingPlugin
  2. # Author: Amanda de Castilho
  3. # Date: August 28, 2018
  4. # Modified: November 16, 2018 by Joshua Pope-Lewis
  5. # Description: This plugin shows custom messages about your print on the Status bar...
  6. # Please look at the 3 options
  7. # - Scolling (SCROLL_LONG_FILENAMES) if enabled in Marlin and you arent printing a small item select this option.
  8. # - Name: By default it will use the name generated by Cura (EG: TT_Test_Cube) - Type a custom name in here
  9. # - Max Layer: Enabling this will show how many layers are in the entire print (EG: Layer 1 of 265!)
  10. from ..Script import Script
  11. from UM.Application import Application
  12. class DisplayFilenameAndLayerOnLCD(Script):
  13. def __init__(self):
  14. super().__init__()
  15. def getSettingDataString(self):
  16. return """{
  17. "name": "Display Filename And Layer On LCD",
  18. "key": "DisplayFilenameAndLayerOnLCD",
  19. "metadata": {},
  20. "version": 2,
  21. "settings":
  22. {
  23. "scroll":
  24. {
  25. "label": "Scroll enabled/Small layers?",
  26. "description": "If SCROLL_LONG_FILENAMES is enabled select this setting however, if the model is small disable this setting!",
  27. "type": "bool",
  28. "default_value": false
  29. },
  30. "name":
  31. {
  32. "label": "Text to display:",
  33. "description": "By default the current filename will be displayed on the LCD. Enter text here to override the filename and display something else.",
  34. "type": "str",
  35. "default_value": ""
  36. },
  37. "startNum":
  38. {
  39. "label": "Initial layer number:",
  40. "description": "Choose which number you prefer for the initial layer, 0 or 1",
  41. "type": "int",
  42. "default_value": 0,
  43. "minimum_value": 0,
  44. "maximum_value": 1
  45. },
  46. "maxlayer":
  47. {
  48. "label": "Display max layer?:",
  49. "description": "Display how many layers are in the entire print on status bar?",
  50. "type": "bool",
  51. "default_value": true
  52. }
  53. }
  54. }"""
  55. def execute(self, data):
  56. max_layer = 0
  57. if self.getSettingValueByKey("name") != "":
  58. name = self.getSettingValueByKey("name")
  59. else:
  60. name = Application.getInstance().getPrintInformation().jobName
  61. if not self.getSettingValueByKey("scroll"):
  62. if self.getSettingValueByKey("maxlayer"):
  63. lcd_text = "M117 Layer "
  64. else:
  65. lcd_text = "M117 Printing Layer "
  66. else:
  67. lcd_text = "M117 Printing " + name + " - Layer "
  68. i = self.getSettingValueByKey("startNum")
  69. for layer in data:
  70. display_text = lcd_text + str(i)
  71. layer_index = data.index(layer)
  72. lines = layer.split("\n")
  73. for line in lines:
  74. if line.startswith(";LAYER_COUNT:"):
  75. max_layer = line
  76. max_layer = max_layer.split(":")[1]
  77. if self.getSettingValueByKey("startNum") == 0:
  78. max_layer = str(int(max_layer) - 1)
  79. if line.startswith(";LAYER:"):
  80. if self.getSettingValueByKey("maxlayer"):
  81. display_text = display_text + " of " + max_layer
  82. if not self.getSettingValueByKey("scroll"):
  83. display_text = display_text + " " + name
  84. else:
  85. if not self.getSettingValueByKey("scroll"):
  86. display_text = display_text + " " + name + "!"
  87. else:
  88. display_text = display_text + "!"
  89. line_index = lines.index(line)
  90. lines.insert(line_index + 1, display_text)
  91. i += 1
  92. final_lines = "\n".join(lines)
  93. data[layer_index] = final_lines
  94. return data