Skip to content

Instantly share code, notes, and snippets.

@madhead
Created May 22, 2024 23:19
Show Gist options
  • Save madhead/85f53ac9ce173132598f63ea6f4f8165 to your computer and use it in GitHub Desktop.
Save madhead/85f53ac9ce173132598f63ea6f4f8165 to your computer and use it in GitHub Desktop.
Display current layer in Cura
from ..Script import Script
from UM.Application import Application
class Layer(Script):
def __init__(self):
super().__init__()
def getSettingDataString(self):
return """{
"name": "Layer on LCD",
"key": "LayerOnLCD",
"metadata": {},
"version": 2,
"settings":
{
"name":
{
"label": "Text to display:",
"description": "By default the current filename will be displayed on the LCD. Enter text here to override the filename and display something else.",
"type": "str",
"default_value": ""
}
}
}"""
def execute(self, data):
max_layer = 0
lcd_text = "M117 "
if self.getSettingValueByKey("name") != "":
name = self.getSettingValueByKey("name")
else:
name = Application.getInstance().getPrintInformation().jobName
lcd_text += name + " @ "
i = 1
for layer in data:
display_text = lcd_text + str(i)
layer_index = data.index(layer)
lines = layer.split("\n")
for line in lines:
if line.startswith(";LAYER_COUNT:"):
max_layer = line
max_layer = max_layer.split(":")[1]
if line.startswith(";LAYER:"):
display_text = display_text + " / " + max_layer
line_index = lines.index(line)
lines.insert(line_index + 1, display_text)
i += 1
final_lines = "\n".join(lines)
data[layer_index] = final_lines
return data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment