mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-05-10 02:59:02 +08:00
69 lines
2.5 KiB
Python
69 lines
2.5 KiB
Python
# Copyright (c) 2019 Ultimaker B.V.
|
|
# The PostProcessingPlugin is released under the terms of the AGPLv3 or higher.
|
|
|
|
from typing import Optional, Tuple
|
|
|
|
from UM.Logger import Logger
|
|
from ..Script import Script
|
|
|
|
class Pause_emt(Script):
|
|
|
|
_layer_keyword = ";LAYER:"
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
def getSettingDataString(self):
|
|
return """{
|
|
"name":"Pause (eMotionTech Printers)",
|
|
"key": "Pause_emt",
|
|
"metadata": {},
|
|
"version": 2,
|
|
"settings":
|
|
{
|
|
"layer_number":
|
|
{
|
|
"label": "Layer",
|
|
"description": "At what layer should pause occur. This will be before the layer starts printing.",
|
|
"unit": "",
|
|
"type": "str",
|
|
"default_value": "1"
|
|
}
|
|
}
|
|
}"""
|
|
|
|
def execute(self, data: list):
|
|
|
|
"""data is a list. Each index contains a layer"""
|
|
layer_nums = self.getSettingValueByKey("layer_number")
|
|
|
|
pause = "M600"
|
|
pause = pause + " ; Generated by PauseStrateo3d plugin"
|
|
|
|
layer_targets = layer_nums.split(",")
|
|
if len(layer_targets) > 0:
|
|
for layer_num in layer_targets:
|
|
layer_num = int(layer_num.strip())
|
|
if layer_num <= len(data):
|
|
index, layer_data = self._searchLayerData(data, layer_num - 1)
|
|
if layer_data is None:
|
|
Logger.log("e", "Layer not found")
|
|
continue
|
|
lines = layer_data.split("\n")
|
|
lines.insert(2, pause)
|
|
final_line = "\n".join(lines)
|
|
data[index] = final_line
|
|
return data
|
|
|
|
## This method returns the data corresponding with the indicated layer number, looking in the gcode for
|
|
# the occurrence of this layer number.
|
|
def _searchLayerData(self, data: list, layer_num: int) -> Tuple[int, Optional[str]]:
|
|
for index, layer_data in enumerate(data):
|
|
first_line = layer_data.split("\n")[0]
|
|
# The first line should contain the layer number at the beginning.
|
|
if first_line[:len(self._layer_keyword)] == self._layer_keyword:
|
|
# If found the layer that we are looking for, then return the data
|
|
if first_line[len(self._layer_keyword):] == str(layer_num):
|
|
return index, layer_data
|
|
return 0, None
|