diff --git a/src/Mod/Assembly/JointObject.py b/src/Mod/Assembly/JointObject.py index 13e426fee0..4420037359 100644 --- a/src/Mod/Assembly/JointObject.py +++ b/src/Mod/Assembly/JointObject.py @@ -509,18 +509,25 @@ class Joint: joint.Offset2 = App.Placement(current_offset, App.Rotation(current_rotation, 0, 0)) def migrationScript4(self, joint): - if hasattr(joint, "Reference1"): - base_name, *sub_names, feature_name = joint.Reference1[1][0].split(".") - ref1 = ".".join((base_name, *sub_names[:-1], feature_name)) - base_name, *sub_names, feature_name = joint.Reference1[1][1].split(".") - ref2 = ".".join((base_name, *sub_names[:-1], feature_name)) - joint.Reference1 = (joint.Reference1[0], [ref1, ref2]) - if hasattr(joint, "Reference2"): - base_name, *sub_names, feature_name = joint.Reference2[1][0].split(".") - ref1 = ".".join((base_name, *sub_names[:-1], feature_name)) - base_name, *sub_names, feature_name = joint.Reference2[1][1].split(".") - ref2 = ".".join((base_name, *sub_names[:-1], feature_name)) - joint.Reference2 = (joint.Reference2[0], [ref1, ref2]) + if hasattr(joint, "Reference1") and joint.Reference1[0] is not None: + doc_name = joint.Reference1[0].Document.Name + sub1 = joint.Reference1[1][0] + sub1 = UtilsAssembly.fixBodyExtraFeatureInSub(doc_name, sub1) + sub2 = joint.Reference1[1][1] + sub2 = UtilsAssembly.fixBodyExtraFeatureInSub(doc_name, sub2) + + if sub1 != joint.Reference1[1][0] or sub2 != joint.Reference1[1][1]: + joint.Reference1 = (joint.Reference1[0], [sub1, sub2]) + + if hasattr(joint, "Reference2") and joint.Reference2[0] is not None: + doc_name = joint.Reference2[0].Document.Name + sub1 = joint.Reference2[1][0] + sub1 = UtilsAssembly.fixBodyExtraFeatureInSub(doc_name, sub1) + sub2 = joint.Reference2[1][1] + sub2 = UtilsAssembly.fixBodyExtraFeatureInSub(doc_name, sub2) + + if sub1 != joint.Reference2[1][0] or sub2 != joint.Reference2[1][1]: + joint.Reference2 = (joint.Reference2[0], [sub1, sub2]) def dumps(self): return None @@ -1791,12 +1798,14 @@ class TaskAssemblyCreateJoint(QtCore.QObject): def addSelection(self, doc_name, obj_name, sub_name, mousePos): rootObj = App.getDocument(doc_name).getObject(obj_name) - # If the sub_name that comes in has extra features in it, remove them. For example a - # Part.Body.Pad.Sketch becomes Part.Body.Sketch and a - # Body.Pad.Sketch becomes Body.sketch - base_name, *path_detail, old_name = sub_name.split(".") - target_link = ".".join((base_name, *path_detail[:-2], old_name)) - ref = [rootObj, [target_link]] + # We do not need the full TNP string like :"Part.Body.Pad.;#a:1;:G0;XTR;:Hc94:8,F.Face6" + # instead we need : "Part.Body.Pad.Face6" + resolved = rootObj.resolveSubElement(sub_name, True) + sub_name = resolved[2] + + sub_name = UtilsAssembly.fixBodyExtraFeatureInSub(doc_name, sub_name) + + ref = [rootObj, [sub_name]] moving_part = self.getMovingPart(ref) # Check if the addition is acceptable (we are not doing this in selection gate to let user move objects) diff --git a/src/Mod/Assembly/UtilsAssembly.py b/src/Mod/Assembly/UtilsAssembly.py index 3c2bdcfee2..dea95a358b 100644 --- a/src/Mod/Assembly/UtilsAssembly.py +++ b/src/Mod/Assembly/UtilsAssembly.py @@ -183,6 +183,40 @@ def isBodySubObject(typeId): ) +def fixBodyExtraFeatureInSub(doc_name, sub_name): + # If the sub_name that comes in has extra features in it, remove them. + # For example : + # "Part.Body.Pad.Edge2" -> "Part.Body.Edge2" + # "Part.Body.Pad.Sketch." -> "Part.Body.Sketch." + # "Body.Pad.Sketch." -> "Body.sketch." + doc = App.getDocument(doc_name) + names = sub_name.split(".") + elt = names.pop() # remove element + + bodyPassed = False + new_sub_name = "" + for obj_name in names: + obj = doc.getObject(obj_name) + if obj is None: + return sub_name + + if bodyPassed and obj.isDerivedFrom("PartDesign::Feature"): + continue # we skip this name! + + if isLink(obj): + obj = obj.getLinkedObject() + doc = obj.Document + + if obj.TypeId == "PartDesign::Body": + bodyPassed = True + + new_sub_name = new_sub_name + obj_name + "." + + new_sub_name = new_sub_name + elt # Put back the element name + + return new_sub_name + + # Deprecated. Kept for migrationScript. def getObjectInPart(objName, part): if part is None: