deal with wrong layer count in Gcode

This commit is contained in:
2019-01-26 17:53:43 +01:00
parent dc84e43d0a
commit ceebad1112
2 changed files with 12 additions and 3 deletions

View File

@@ -6,7 +6,7 @@ import re
from math import isclose
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(message)s')
format='%(asctime)s - %(levelname)s: %(message)s')
FLOAT_OR_INT = r'\d+(\.\d*)?'
@@ -59,6 +59,12 @@ class GcodeFileAnalyzer:
layerCountMatch = RE_LAYER_COUNT.search(fullCode)
self.layerCount = int(layerCountMatch.group(1))
layersList = RE_LAYER.findall(fullCode)
if len(layersList) != self.layerCount:
logging.warning('Gcode states wrong layer count {}. But found {} layers.'
.format(layerCountMatch.group(0), len(layersList)))
self.layerCount = len(layersList)
layersIndices = [self.lines.index(layer) for layer in layersList] + [startOfFooterIndex]
self.layers = [Layer(self.lines[i:j]) for i, j in zip(layersIndices[:-1], layersIndices[1:])]
@@ -202,6 +208,8 @@ class Layer:
if __name__ == '__main__':
GcodeFileAnalyzer.SplitFileAtLayers('test/BigL.gcode', ['2.8001mm', 300])
# GcodeFileAnalyzer.SplitFileAtLayers('test/BigL.gcode', ['2.8001mm', 300])
# GcodeFileAnalyzer.SplitFileAtLayers(r"Q:\DIY\3Dprint\Models\Thingiverse\Murmelbahnen\The_Cyclone_triple_lift_triple_track_marble_machine\files\gcode\Marble_machine.gcode",
# [118, 160, 240, 360, 480])
# ['97.3mm', 405, 480])
GcodeFileAnalyzer.SplitFileAtLayers(r"Q:\DIY\3Dprint\Models\Thingiverse\Shuttle\Shuttle.gcode",
[334])