From 180b4ef5ec1f12e711b79784d161c47b10160a05 Mon Sep 17 00:00:00 2001 From: Joerg Date: Mon, 31 Oct 2022 19:07:24 +0100 Subject: [PATCH] works with Cura 5.1.1 --- GcodeFileSplitter.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/GcodeFileSplitter.py b/GcodeFileSplitter.py index e7e5cf4..b768fda 100644 --- a/GcodeFileSplitter.py +++ b/GcodeFileSplitter.py @@ -11,6 +11,7 @@ logging.basicConfig(level=logging.DEBUG, FLOAT_OR_INT = r'-?\d+(\.\d*)?' RE_ENGINE_VERSION = re.compile(r'SteamEngine (\d+\.\d+\.\d+)') +RE_ENGINE_V5 = re.compile(r'\n(.*SteamEngine main.*)\n') RE_LAYER_COUNT = re.compile(r';LAYER_COUNT:(\d+)', re.MULTILINE) RE_LAYER_NUMBER = re.compile(r';LAYER:(\d+)') RE_FOOTER_START = re.compile(r'(;TIME_ELAPSED:\d+\.\d+)\n[^;]', re.MULTILINE) @@ -55,7 +56,18 @@ class GcodeFileAnalyzer: fullCode = '\n'.join(self.lines) versionMatch = RE_ENGINE_VERSION.search(fullCode) - self.curaVersion = tuple(int(v) for v in versionMatch.group(1).split('.')) + if versionMatch: + self.curaVersion = tuple(int(v) for v in versionMatch.group(1).split('.')) + logging.info('Cura version {self.curaVersion}') + else: + v5engineMatch = RE_ENGINE_V5.search(fullCode) + if v5engineMatch: + logging.info('Cura version not specified. Assuming 5.x') + logging.info(f' -> {v5engineMatch.group(1)}') + self.curaVersion = (5, 0, 0) + else: + raise ValueError('Could not find ";Generated with Cura_SteamEngine" ' + 'in GCODE. Can\'t proceed') # Find footer footerStartMatch = RE_FOOTER_START.search(fullCode) @@ -240,5 +252,5 @@ if __name__ == '__main__': # [124]) # GcodeFileAnalyzer.SplitFileAtLayers(r"Q:\DIY\3Dprint\Models\Thingiverse\MoonLamp\gcode\moon5inches.gcode", # [100, 200, 400, 600, 700]) - GcodeFileAnalyzer.SplitFileAtLayers(r"Q:\DIY\3Dprint\Models\Pi\PiJukebox\bottom_2020-11-22\bottom.gcode", - [87]) + GcodeFileAnalyzer.SplitFileAtLayers(r"Q:\DIY\3Dprint\Models\Benjamin\Vier_Cura5.1.1.gcode", + [42])