From c8e163df7e38466c75b79786fba30291fa7a9acf Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Thu, 6 Mar 2025 16:15:34 +0100 Subject: [PATCH] Assembly: Select LCS elements when LCS is in body * Make it possible to select LCS elements the the LCS is in a body --- src/Mod/Assembly/UtilsAssembly.py | 43 ++++++++++++++++++------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/Mod/Assembly/UtilsAssembly.py b/src/Mod/Assembly/UtilsAssembly.py index 692a742f8d..b88ca8b24e 100644 --- a/src/Mod/Assembly/UtilsAssembly.py +++ b/src/Mod/Assembly/UtilsAssembly.py @@ -177,15 +177,7 @@ def getObject(ref): return obj elif obj.TypeId == "PartDesign::Body": - if i + 1 < len(names): - obj2 = None - for obji in obj.OutList: - if obji.Name == names[i + 1]: - obj2 = obji - break - if obj2 and isBodySubObject(obj2): - return obj2 - return obj + return process_body(obj, obj, names, i) elif obj.isDerivedFrom("Part::Feature"): # primitive, fastener, gear ... @@ -194,15 +186,7 @@ def getObject(ref): elif isLink(obj): linked_obj = obj.getLinkedObject() if linked_obj.TypeId == "PartDesign::Body": - if i + 1 < len(names): - obj2 = None - for obji in linked_obj.OutList: - if obji.Name == names[i + 1]: - obj2 = obji - break - if obj2 and isBodySubObject(obj2): - return obj2 - return obj + return process_body(linked_obj, obj, names, i) elif linked_obj.isDerivedFrom("Part::Feature"): return obj else: @@ -212,6 +196,29 @@ def getObject(ref): return None +def process_body(body, returnObj, names, i): + # If there's a next name, it could either be elementName, in which case we can return the Body. + # But it could be a subobject like Sketch or datums. + if i + 1 < len(names): + obj2 = None + for obji in body.OutList: + if obji.Name == names[i + 1]: + obj2 = obji + break + if obj2 and isBodySubObject(obj2): + # obj2 can be a LCS or a Sketch. But it can also be a LCS's Axis or plane. + if i + 2 < len(names): + obj3 = None + for obji in obj2.OutList: + if obji.Name == names[i + 2]: + obj3 = obji + break + if obj3 and isBodySubObject(obj3): + return obj3 + return obj2 + return returnObj + + def isBodySubObject(obj): return ( obj.isDerivedFrom("Sketcher::SketchObject")