def restorePlacementEE(self, obj): # only attempt this on fully restored objects if self.isLoaded(obj) and obj.LinkedObject.isValid(): # if it's indeed an Asm4 object # LCS_Origin.Placement * AttachmentOffset * varTmpDoc_3#LCS_Origin.Placement ^ -1 if Asm4.isAsm4EE(obj) and (obj.SolverId == 'Asm4EE' or obj.SolverId == 'Placement::ExpressionEngine'): # retrieve the info from the object's properties (a_Link, sep, a_LCS) = obj.AttachedTo.partition('#') if a_Link == 'Parent Assembly': a_Part = None else: a_Part = obj.Document.getObject( a_Link).LinkedObject.Document.Name l_Part = obj.LinkedObject.Document.Name l_LCS = obj.AttachedBy[1:] # build the expression expr = Asm4.makeExpressionPart(a_Link, a_Part, a_LCS, l_Part, l_LCS) # set the expression obj.setExpression('Placement', expr)
def Apply( self ): # get the instance to attach to: # it's either the top level assembly or a sister App::Link if self.parentList.currentText() == 'Parent Assembly': a_Link = 'Parent Assembly' a_Part = None elif self.parentList.currentIndex() > 1: parent = self.parentTable[ self.parentList.currentIndex() ] a_Link = parent.Name a_Part = parent.LinkedObject.Document.Name else: a_Link = None a_Part = None # the attachment LCS's name in the parent # check that something is selected in the QlistWidget if self.attLCSlist.selectedItems(): a_LCS = self.attLCStable[ self.attLCSlist.currentRow() ].Name else: a_LCS = None # the linked App::Part's name l_Part = self.selectedObj.LinkedObject.Document.Name # the LCS's name in the linked part to be used for its attachment # check that something is selected in the QlistWidget if self.partLCSlist.selectedItems(): #l_LCS = self.partLCSlist.selectedItems()[0].text() l_LCS = self.partLCStable[ self.partLCSlist.currentRow() ].Name else: l_LCS = None # check that all of them have something in # constrName has been checked at the beginning if a_Link and a_LCS and l_Part and l_LCS : # add the Asm4 properties if it's a pure App::Link Asm4.makeAsmProperties(self.selectedObj) # self.selectedObj.AssemblyType = 'Part::Link' self.selectedObj.AttachedBy = '#'+l_LCS self.selectedObj.AttachedTo = a_Link+'#'+a_LCS self.selectedObj.SolverId = 'Placement::ExpressionEngine' # build the expression for the ExpressionEngine # this is where all the magic is, see: # # https://forum.freecadweb.org/viewtopic.php?p=278124#p278124 # # as of FreeCAD v0.19 the syntax is different: # https://forum.freecadweb.org/viewtopic.php?f=17&t=38974&p=337784#p337784 # # expr = ParentLink.Placement * ParentPart#LCS.Placement * constr_LinkName.AttachmentOffset * LinkedPart#LCS.Placement ^ -1' # expr = LCS_in_the_assembly.Placement * constr_LinkName.AttachmentOffset * LinkedPart#LCS.Placement ^ -1' expr = Asm4.makeExpressionPart( a_Link, a_Part, a_LCS, l_Part, l_LCS ) # load the expression into the link's Expression Engine self.selectedObj.setExpression('Placement', expr ) # recompute the object to apply the placement: self.selectedObj.recompute() self.rootAssembly.recompute(True) return True else: FCC.PrintWarning("Problem in selections\n") return False