DisplayFilenameAndLayerOnLCD.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 5 options
  7. # - Scrolling (SCROLL_LONG_FILENAMES) if enabled in Marlin and you aren't 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. # - Start Num: Choose which number you prefer for the initial layer, 0 or 1
  10. # - Max Layer: Enabling this will show how many layers are in the entire print (EG: Layer 1 of 265!)
  11. # - Add prefix 'Printing': Enabling this will add the prefix 'Printing'
  12. from ..Script import Script
  13. from UM.Application import Application
  14. class DisplayFilenameAndLayerOnLCD(Script):
  15. def __init__(self):
  16. super().__init__()
  17. def getSettingDataString(self):
  18. return """{
  19. "name": "Display Filename And Layer On LCD",
  20. "key": "DisplayFilenameAndLayerOnLCD",
  21. "metadata": {},
  22. "version": 2,
  23. "settings":
  24. {
  25. "scroll":
  26. {
  27. "label": "Scroll enabled/Small layers?",
  28. "description": "If SCROLL_LONG_FILENAMES is enabled select this setting however, if the model is small disable this setting!",
  29. "type": "bool",
  30. "default_value": false
  31. },
  32. "name":
  33. {
  34. "label": "Text to display:",
  35. "description": "By default the current filename will be displayed on the LCD. Enter text here to override the filename and display something else.",
  36. "type": "str",
  37. "default_value": ""
  38. },
  39. "startNum":
  40. {
  41. "label": "Initial layer number:",
  42. "description": "Choose which number you prefer for the initial layer, 0 or 1",
  43. "type": "int",
  44. "default_value": 0,
  45. "minimum_value": 0,
  46. "maximum_value": 1
  47. },
  48. "maxlayer":
  49. {
  50. "label": "Display max layer?:",
  51. "description": "Display how many layers are in the entire print on status bar?",
  52. "type": "bool",
  53. "default_value": true
  54. },
  55. "addPrefixPrinting":
  56. {
  57. "label": "Add prefix 'Printing'?",
  58. "description": "This will add the prefix 'Printing'",
  59. "type": "bool",
  60. "default_value": true
  61. }
  62. }
  63. }"""
  64. def execute(self, data):
  65. max_layer = 0
  66. lcd_text = "M117 "
  67. if self.getSettingValueByKey("name") != "":
  68. name = self.getSettingValueByKey("name")
  69. else:
  70. name = Application.getInstance().getPrintInformation().jobName
  71. if self.getSettingValueByKey("addPrefixPrinting"):
  72. lcd_text += "Printing "
  73. if not self.getSettingValueByKey("scroll"):
  74. lcd_text += "Layer "
  75. else:
  76. lcd_text += name + " - Layer "
  77. i = self.getSettingValueByKey("startNum")
  78. for layer in data:
  79. display_text = lcd_text + str(i)
  80. layer_index = data.index(layer)
  81. lines = layer.split("\n")
  82. for line in lines:
  83. if line.startswith(";LAYER_COUNT:"):
  84. max_layer = line
  85. max_layer = max_layer.split(":")[1]
  86. if self.getSettingValueByKey("startNum") == 0:
  87. max_layer = str(int(max_layer) - 1)
  88. if line.startswith(";LAYER:"):
  89. if self.getSettingValueByKey("maxlayer"):
  90. display_text = display_text + " of " + max_layer
  91. if not self.getSettingValueByKey("scroll"):
  92. display_text = display_text + " " + name
  93. else:
  94. if not self.getSettingValueByKey("scroll"):
  95. display_text = display_text + " " + name + "!"
  96. else:
  97. display_text = display_text + "!"
  98. line_index = lines.index(line)
  99. lines.insert(line_index + 1, display_text)
  100. i += 1
  101. final_lines = "\n".join(lines)
  102. data[layer_index] = final_lines
  103. return data