From f6c5dc82f9363e7878a63d717dec46509ca67aa1 Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Mon, 1 Dec 2025 18:01:19 +0100 Subject: [PATCH] Assembly: Fix selection during joint edition (#25687) --- src/Mod/Assembly/JointObject.py | 7 ++++-- src/Mod/Assembly/UtilsAssembly.py | 40 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/Mod/Assembly/JointObject.py b/src/Mod/Assembly/JointObject.py index 01f68ed750..37e81f464c 100644 --- a/src/Mod/Assembly/JointObject.py +++ b/src/Mod/Assembly/JointObject.py @@ -1839,8 +1839,11 @@ class TaskAssemblyCreateJoint(QtCore.QObject): self.refs.append(ref1) self.refs.append(ref2) - Gui.Selection.addSelection(ref1[0].Document.Name, ref1[0].Name, ref1[1][0]) - Gui.Selection.addSelection(ref2[0].Document.Name, ref2[0].Name, ref2[1][0]) + sub1 = UtilsAssembly.addTipNameToSub(ref1) + sub2 = UtilsAssembly.addTipNameToSub(ref2) + + Gui.Selection.addSelection(ref1[0].Document.Name, ref1[0].Name, sub1) + Gui.Selection.addSelection(ref2[0].Document.Name, ref2[0].Name, sub2) self.jForm.angleSpinbox.setProperty("rawValue", self.joint.Angle.Value) self.jForm.distanceSpinbox.setProperty("rawValue", self.joint.Distance.Value) diff --git a/src/Mod/Assembly/UtilsAssembly.py b/src/Mod/Assembly/UtilsAssembly.py index aca345ff0e..04b4fefb17 100644 --- a/src/Mod/Assembly/UtilsAssembly.py +++ b/src/Mod/Assembly/UtilsAssembly.py @@ -259,6 +259,46 @@ def fixBodyExtraFeatureInSub(doc_name, sub_name): return new_sub_name +def addTipNameToSub(ref): + """ + Checks if the object referenced is a PartDesign::Body (or a Link to one). + If so, it injects the Tip Name before the element name in the sub string. + This is required for Gui.Selection to correctly highlight the geometry in the 3D View. + Example: 'Body.Face1' -> 'Body.Pad.Face1' + Example: 'Link.Face1' -> 'Link.Pad.Face1' + """ + if not isRefValid(ref, 1): + return "" + + sub = ref[1][0] + + # Resolve the actual object being pointed to + obj = getObject(ref) + + target_body = None + + if obj: + if obj.TypeId == "PartDesign::Body": + target_body = obj + elif isLink(obj): + linked = obj.getLinkedObject() + if linked and linked.TypeId == "PartDesign::Body": + target_body = linked + + if target_body and target_body.Tip: + split_sub = sub.split(".") + if len(split_sub) > 0: + element = split_sub.pop() + if not element: # Empty element name means the whole body is selected + return sub + + split_sub.append(target_body.Tip.Name) + split_sub.append(element) + return ".".join(split_sub) + + return sub + + # Deprecated. Kept for migrationScript. def getObjectInPart(objName, part): if part is None: