diff --git a/README.md b/README.md index 35f076e..c5d559e 100644 --- a/README.md +++ b/README.md @@ -8,20 +8,20 @@ It shows the percentage, the current layer and the total layer count: - NavBar: Progress: 50% Layer: 60/120 **ATTENTION:** -- The layer information output only works with Cura generated G-Code, because Cura insert the layer information (layer, layerCount) as comments in the file. +- The layer information output only works with Cura/Simplify3D generated G-Code, because these Slicer insert the layer information as comments in the file. - If the layer comments couldn't found, only the percentage will be displayed - You need to upload your G-Code after installation of the plugin again (if you want to reuse already stored models in OctoPrint), because while uploading the G-Code is modfied -**CURA Comment Format Example:** -``` -;LAYER_COUNT:330 -;LAYER:0 -``` +**Comment Format Examples:** + +CURA: ```;LAYER:10``` + +Simplify3D: ```; layer 10, Z = 1.640``` The implementation is based on four steps: 1. PreProcessing the uploaded G-Code (replace layer-comment with M117) -2. Read total layer count from G-Code before start +2. Read total layer count from G-Code before start (used last layer-comment) 3. G-Code-Hook to collect the current layer information (M117-command from step 1) 4. Progress-Hook to write all information to the printer/navbar diff --git a/octoprint_DisplayLayerProgress/__init__.py b/octoprint_DisplayLayerProgress/__init__.py index 4173ceb..7c8899d 100644 --- a/octoprint_DisplayLayerProgress/__init__.py +++ b/octoprint_DisplayLayerProgress/__init__.py @@ -20,7 +20,8 @@ ## CONSTs NOT_PRESENT = "NOT-PRESENT" LAYER_MESSAGE_PREFIX = "M117 INDICATOR-Layer" -LAYER_EXPRESSION = ";LAYER:([0-9]*)" +LAYER_EXPRESSION_CURA = ";LAYER:([0-9]*)" +LAYER_EXPRESSION_S3D = "; layer ([0-9]*),*" #LAYER_COUNT_EXPRESSION = ";LAYER_COUNT:([0-9]*)" --> not usful for other slicer LAYER_COUNT_EXPRESSION = LAYER_MESSAGE_PREFIX+"([0-9]*)" @@ -28,19 +29,24 @@ class LayerDetectorFileProcessor(octoprint.filemanager.util.LineProcessorStream) def process_line(self, line): - markerLayer = LAYER_EXPRESSION - pattern = re.compile(markerLayer) - matched = pattern.match(line) - if matched: - currentLayer = matched.group(1) - line = LAYER_MESSAGE_PREFIX + currentLayer + "\r\n" + line = self._checkLineForLayerComment(line, LAYER_EXPRESSION_CURA) + line = self._checkLineForLayerComment(line, LAYER_EXPRESSION_S3D) #line = strip_comment(line).strip() DO NOT USE, because total-layer count disapears if not len(line): return None return line + def _checkLineForLayerComment(self, line, commentPattern): + pattern = re.compile(commentPattern) + matched = pattern.match(line) + + if matched: + currentLayer = matched.group(1) + line = LAYER_MESSAGE_PREFIX + currentLayer + "\r\n" + + return line class DisplaylayerprogressPlugin(octoprint.plugin.SettingsPlugin, octoprint.plugin.AssetPlugin,