From 37bea1ee5d741ae265cf7ce580a9dae66cb5be5c Mon Sep 17 00:00:00 2001 From: Billy Huddleston Date: Sun, 4 Jan 2026 13:39:20 -0500 Subject: [PATCH] CAM: Fix duplicate label issues with toolbits Addresses problems caused by the "Allow duplicate object labels in one document" option. Toolbit sub-objects now always get unique labels by temporarily disabling this option during copy, preventing expression and property binding errors. Also ensures tool controllers always use the "TC: " prefix for consistency. src/Mod/CAM/Path/Tool/shape/models/base.py: - Temporarily disable DuplicateLabels during shape copy to enforce unique labels src/Mod/CAM/Path/Main/Gui/Job.py: - Add "TC: " prefix to tool controller names when adding from the Job panel --- src/Mod/CAM/Path/Main/Gui/Job.py | 4 +++- src/Mod/CAM/Path/Tool/shape/models/base.py | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Mod/CAM/Path/Main/Gui/Job.py b/src/Mod/CAM/Path/Main/Gui/Job.py index 509a5af80e..56a497546f 100644 --- a/src/Mod/CAM/Path/Main/Gui/Job.py +++ b/src/Mod/CAM/Path/Main/Gui/Job.py @@ -1149,7 +1149,9 @@ class TaskPanel: toolbit = selector.get_selected_tool() toolbit.attach_to_doc(FreeCAD.ActiveDocument) toolNum = self.obj.Proxy.nextToolNumber() - tc = PathToolControllerGui.Create(name=toolbit.label, tool=toolbit.obj, toolNumber=toolNum) + tc = PathToolControllerGui.Create( + name=f"TC: {toolbit.label}", tool=toolbit.obj, toolNumber=toolNum + ) self.obj.Proxy.addToolController(tc) FreeCAD.ActiveDocument.recompute() diff --git a/src/Mod/CAM/Path/Tool/shape/models/base.py b/src/Mod/CAM/Path/Tool/shape/models/base.py index 3d4ccd27d1..77cfa8c63b 100644 --- a/src/Mod/CAM/Path/Tool/shape/models/base.py +++ b/src/Mod/CAM/Path/Tool/shape/models/base.py @@ -718,8 +718,23 @@ class ToolBitShape(Asset): # Recompute the document to apply property changes tmp_doc.recompute() - # Copy the body to the given document without immediate compute. - return doc.copyObject(shape, True) + # Temporarily disable duplicate labels to let FreeCAD automatically + # make labels unique during the copy operation + + param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Document") + original_setting = param.GetBool("DuplicateLabels", False) + + try: + # Disable duplicate labels temporarily + param.SetBool("DuplicateLabels", False) + + # Copy the body - FreeCAD will now automatically make labels unique + copied_shape = doc.copyObject(shape, True) + + return copied_shape + finally: + # Restore the original setting + param.SetBool("DuplicateLabels", original_setting) """ Retrieves the thumbnail data for the tool bit shape in PNG format.