From 131737a4fce40d7a01c67ef56c47a3e50aeafa72 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Mon, 11 Aug 2025 10:32:52 -0500 Subject: [PATCH] CAM: Fix bug with loop completion (#22877) * fixes #22876 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- src/Mod/CAM/PathCommands.py | 47 ++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/src/Mod/CAM/PathCommands.py b/src/Mod/CAM/PathCommands.py index b14a3c9431..b95b95d57c 100644 --- a/src/Mod/CAM/PathCommands.py +++ b/src/Mod/CAM/PathCommands.py @@ -85,32 +85,47 @@ class _CommandSelectLoop: return False def Activated(self): - from PathScripts.PathUtils import horizontalEdgeLoop - from PathScripts.PathUtils import horizontalFaceLoop + from PathScripts.PathUtils import horizontalEdgeLoop, horizontalFaceLoop + + if not FreeCADGui.Selection.getSelectionEx(): + return sel = FreeCADGui.Selection.getSelectionEx()[0] + if not sel.SubObjects: + return + obj = sel.Object - edge1 = sel.SubObjects[0] - if "Face" in sel.SubElementNames[0]: - loop = horizontalFaceLoop(sel.Object, sel.SubObjects[0], sel.SubElementNames) + sub = sel.SubObjects + names = sel.SubElementNames + loopwire = None + + # Face selection + if "Face" in names[0]: + loop = horizontalFaceLoop(obj, sub[0], names) if loop: FreeCADGui.Selection.clearSelection() - FreeCADGui.Selection.addSelection(sel.Object, loop) - loopwire = [] - elif len(sel.SubObjects) == 1: - loopwire = horizontalEdgeLoop(obj, edge1) - else: - edge2 = sel.SubObjects[1] - loopwire = loopdetect(obj, edge1, edge2) + FreeCADGui.Selection.addSelection(obj, loop) + return - if loopwire: - FreeCADGui.Selection.clearSelection() + # One edge selected + elif len(sub) == 1: + loopwire = horizontalEdgeLoop(obj, sub[0]) + + # Two edges selected + elif len(sub) >= 2: + loopwire = loopdetect(obj, sub[0], sub[1]) + + if hasattr(loopwire, "Edges") and loopwire.Edges: elist = obj.Shape.Edges + FreeCADGui.Selection.clearSelection() for i in loopwire.Edges: for e in elist: if e.hashCode() == i.hashCode(): - FreeCADGui.Selection.addSelection(obj, "Edge" + str(elist.index(e) + 1)) - elif FreeCAD.GuiUp: + FreeCADGui.Selection.addSelection(obj, f"Edge{elist.index(e) + 1}") + return + + # Final fallback + if FreeCAD.GuiUp: QtGui.QMessageBox.information( None, QT_TRANSLATE_NOOP("CAM_SelectLoop", "Feature Completion"),