From b74a3b5270779bd64e2e6e514d5e60dcb59e86d1 Mon Sep 17 00:00:00 2001 From: jffmichi Date: Sat, 21 Jun 2025 19:49:49 +0200 Subject: [PATCH] CAM: simplify Order Output By Tool logic and fix #21969 (#21970) Co-authored-by: jffmichi <> --- src/Mod/CAM/Path/Post/Processor.py | 51 ++++++++++++++++-------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/src/Mod/CAM/Path/Post/Processor.py b/src/Mod/CAM/Path/Post/Processor.py index 1c153c309a..7cffd34264 100644 --- a/src/Mod/CAM/Path/Post/Processor.py +++ b/src/Mod/CAM/Path/Post/Processor.py @@ -222,6 +222,13 @@ class PostProcessor: curlist = [] # list of ops for tool, will repeat for each fixture sublist = [] # list of ops for output splitting + def commitToPostlist(): + if len(curlist) > 0: + for fixture in fixturelist: + sublist.append(fixture) + sublist.extend(curlist) + postlist.append((toolstring, sublist)) + Path.Log.track(self._job.PostProcessorOutputFile) for idx, obj in enumerate(self._job.Operations.Group): Path.Log.track(obj.Label) @@ -231,40 +238,36 @@ class PostProcessor: Path.Log.track() continue - # Determine the proper string for the Op's TC tc = PathUtil.toolControllerForOp(obj) - if tc is None: - tcstring = "None" - elif "%T" in self._job.PostProcessorOutputFile: - tcstring = f"{tc.ToolNumber}" - else: - tcstring = re.sub(r"[^\w\d-]", "_", tc.Label) - Path.Log.track(toolstring) + + # The operation has no ToolController or uses the same + # ToolController as the previous operations if tc is None or tc.ToolNumber == currTool: + # Queue current operation curlist.append(obj) - elif tc.ToolNumber != currTool and currTool is None: # first TC - sublist.append(tc) - curlist.append(obj) - currTool = tc.ToolNumber - toolstring = tcstring - elif tc.ToolNumber != currTool and currTool is not None: # TC - for fixture in fixturelist: - sublist.append(fixture) - sublist.extend(curlist) - postlist.append((toolstring, sublist)) + # The operation is the first operation or uses a different + # ToolController as the previous operations + + else: + # Commit previous operations + commitToPostlist() + + # Queue current ToolController and operation sublist = [tc] curlist = [obj] currTool = tc.ToolNumber - toolstring = tcstring - if idx == len(self._job.Operations.Group) - 1: # Last operation. - for fixture in fixturelist: - sublist.append(fixture) - sublist.extend(curlist) + # Determine the proper string for the operation's + # ToolController + if "%T" in self._job.PostProcessorOutputFile: + toolstring = f"{tc.ToolNumber}" + else: + toolstring = re.sub(r"[^\w\d-]", "_", tc.Label) - postlist.append((toolstring, sublist)) + # Commit remaining operations + commitToPostlist() elif orderby == "Operation": Path.Log.debug("Ordering by Operation")