def Activated(self): self.selObj = None # get the selected object if Asm4.getSelectedContainer(): self.selObj = Asm4.getSelectedContainer() elif Asm4.getSelectedLink(): self.selObj = Asm4.getSelectedLink() # should be unnecessary, but who knows if self.selObj: # initialise the UI self.selectedPart.setText(self.selObj.Name) proposedName = self.selObj.Label+'_sym' self.mirroredPartName.setText(proposedName) self.UI.show()
def IsActive(self): # Will handle LCSs only for the Assembly4 model if Asm4.getSelectedLink() or Asm4.getModelSelected(): # treats all container types : Body and Part #if Asm4.getSelectedContainer() or Asm4.checkModel() or Asm4.getSelectedLink(): return True return False
def Activated(self): #Handle single selected App::Link selectedLink = None parentAssembly = None selection = Asm4.getSelectedLink() if not selection: # This shouldn't happen FCC.PrintWarning( "This is not an error message you are supposed to see, something went wrong\n" ) return else: parent = selection.getParentGeoFeatureGroup() # only handle if the parent is at the root of the document: if parent and parent.TypeId == 'App::Part' and parent.getParentGeoFeatureGroup( ) is None: # only accept Asm4 Models as assemblies # this is self-imposed, works also without an Asm4 Model if parent.Name == 'Model': # launch the UI in the task panel Gui.Control.showDialog(placeLinkUI()) else: Asm4.warningBox( 'Please select a link in the assembly Model') else: Asm4.warningBox('Please select a link in the assembly Model.') return
def RestoreConfiguration(docName): FCC.PrintMessage('Restoring configuration "' + docName + '"\n') doc = getConfig(docName, 'Configurations') model = Asm4.checkModel() link = Asm4.getSelectedLink() if link: RestoreObject(doc, link) else: RestoreSubObjects(doc, model) App.ActiveDocument.recompute()
def Activated(self): #global processedLinks # reset processed links cache processedLinks = [] model = Asm4.getModelSelected() if model: for objName in model.getSubObjects(): Asm4.showChildLCSs(model.getSubObject(objName, 1), False, processedLinks) else: Asm4.showChildLCSs(Asm4.getSelectedLink(), False, processedLinks)
def Activated(self): #global processedLinks # reset processed links cache processedLinks = [] container = Asm4.getSelectedContainer() if not container: container = Asm4.checkModel() link = Asm4.getSelectedLink() if link: showChildLCSs(link, False, processedLinks) elif container: for objName in container.getSubObjects(1): showChildLCSs(container.getSubObject(objName, 1), False, processedLinks)
def SaveConfiguration(self, confName, description): FCC.PrintMessage('Saving configuration to "' + confName + '"\n') conf = getConfig(confName, 'Configurations') if conf: confirm = Asm4.confirmBox('Override configuration in "' + confName + '"?') if not confirm: FCC.PrintMessage('Cancel save...\n') return else: setConfigDescription(conf, description) else: conf = self.createConfig(confName, description, 'Configurations') model = App.ActiveDocument.getObject('Model') link = Asm4.getSelectedLink() if link: self.SaveObject(conf, link) else: self.SaveSubObjects(conf, model) conf.recompute(True)
def __init__(self): self.base = QtGui.QWidget() self.form = self.base iconFile = os.path.join(Asm4.iconPath, 'Place_Link.svg') self.form.setWindowIcon(QtGui.QIcon(iconFile)) self.form.setWindowTitle('Place linked Part') # check that we have selected two LCS or an App::Link object self.selectedLink = [] self.selectedLCSA = None self.selectedLinkB = None self.selectedLCSB = None selection = Asm4.getSelectedLink() #selectedLCSPair = Asm4.getLinkAndDatum2() self.Xtranslation = 0.00 self.Ytranslation = 0.00 self.Ztranslation = 0.00 self.XrotationAngle = 0.00 self.YrotationAngle = 0.00 self.ZrotationAngle = 0.00 # draw the GUI, objects are defined later down self.drawUI() global taskUI taskUI = self #Handle single selected App::Link if not selection: # This shouldn't happen FCC.PrintWarning( "This is not an error message you are supposed to see, something went wrong\n" ) Gui.Control.closeDialog() else: self.selectedLink = selection Asm4.makeAsmProperties(self.selectedLink) #save original AttachmentOffset of linked part self.old_LinkAttachmentOffset = self.selectedLink.AttachmentOffset self.old_LinkRotation = self.selectedLink.AttachmentOffset.Rotation self.old_LinkPosition = self.selectedLink.AttachmentOffset.Base # default values correspond to original AttachmentOffset of linked part self.Xtranslation = self.old_LinkPosition[0] self.Ytranslation = self.old_LinkPosition[1] self.Ztranslation = self.old_LinkPosition[2] self.XrotationAngle = self.old_LinkRotation.toEuler()[0] self.YrotationAngle = self.old_LinkRotation.toEuler()[1] self.ZrotationAngle = self.old_LinkRotation.toEuler()[2] # save previous view properties self.old_OverrideMaterial = self.selectedLink.ViewObject.OverrideMaterial self.old_DrawStyle = self.selectedLink.ViewObject.DrawStyle self.old_LineWidth = self.selectedLink.ViewObject.LineWidth self.old_DiffuseColor = self.selectedLink.ViewObject.ShapeMaterial.DiffuseColor self.old_Transparency = self.selectedLink.ViewObject.ShapeMaterial.Transparency # set new view properties self.selectedLink.ViewObject.OverrideMaterial = True self.selectedLink.ViewObject.DrawStyle = DrawStyle self.selectedLink.ViewObject.LineWidth = LineWidth self.selectedLink.ViewObject.ShapeMaterial.DiffuseColor = DiffuseColor self.selectedLink.ViewObject.ShapeMaterial.Transparency = Transparency # get the current active document to avoid errors if user changes tab self.activeDoc = App.activeDocument() # the parent (top-level) assembly is the App::Part called Model (hard-coded) self.parentAssembly = self.activeDoc.Model # check that the link is an Asm4 link: self.isAsm4EE = False if hasattr(self.selectedLink, 'AssemblyType'): if self.selectedLink.AssemblyType == 'Asm4EE' or self.selectedLink.AssemblyType == '': self.isAsm4EE = True else: Asm4.warningBox( "This Link's assembly type doesn't correspond to this WorkBench" ) return # initialize the UI with the current data self.attLCStable = [] self.initUI() # now self.parentList and self.parentTable are available # find all the linked parts in the assembly for objName in self.parentAssembly.getSubObjects(): # remove the trailing . obj = self.activeDoc.getObject(objName[0:-1]) if obj.TypeId == 'App::Link' and hasattr(obj.LinkedObject, 'isDerivedFrom'): if obj.LinkedObject.isDerivedFrom( 'App::Part') or obj.LinkedObject.isDerivedFrom( 'PartDesign::Body'): # ... except if it's the selected link itself if obj != self.selectedLink: self.parentTable.append(obj) # add to the drop-down combo box with the assembly tree's parts objIcon = obj.LinkedObject.ViewObject.Icon objText = Asm4.nameLabel(obj) self.parentList.addItem(objIcon, objText, obj) # find all the LCS in the selected link self.partLCStable = Asm4.getPartLCS(self.selectedLink.LinkedObject) # build the list self.partLCSlist.clear() for lcs in self.partLCStable: newItem = QtGui.QListWidgetItem() newItem.setText(Asm4.nameLabel(lcs)) newItem.setIcon(lcs.ViewObject.Icon) self.partLCSlist.addItem(newItem) # get the old values if self.isAsm4EE: self.old_AO = self.selectedLink.AttachmentOffset self.old_linkLCS = self.selectedLink.AttachedBy[1:] (self.old_Parent, separator, self.old_parentLCS) = self.selectedLink.AttachedTo.partition('#') else: self.old_AO = [] self.old_Parent = '' self.old_EE = '' # get and store the current expression engine: self.old_EE = Asm4.placementEE(self.selectedLink.ExpressionEngine) # decode the old ExpressionEngine old_Parent = '' old_ParentPart = '' old_attLCS = '' constrName = '' linkedDoc = '' old_linkLCS = '' # if the decode is unsuccessful, old_Expression is set to False and the other things are set to 'None' (old_Parent, old_attLCS, old_linkLCS) = Asm4.splitExpressionLink(self.old_EE, self.old_Parent) # find the old LCS in the list of LCS of the linked part... # MatchExactly, MatchContains, MatchEndsWith ... lcs_found = self.partLCSlist.findItems(old_linkLCS, QtCore.Qt.MatchExactly) if not lcs_found: lcs_found = self.partLCSlist.findItems(old_linkLCS + ' (', QtCore.Qt.MatchStartsWith) if lcs_found: # ... and select it self.partLCSlist.setCurrentItem(lcs_found[0]) # find the oldPart in the part list... if old_Parent == 'Parent Assembly': parent_found = True parent_index = 1 else: parent_found = False parent_index = 1 for item in self.parentTable[1:]: if item.Name == old_Parent: parent_found = True break else: parent_index = parent_index + 1 if not parent_found: parent_index = 0 self.parentList.setCurrentIndex(parent_index) # this should have triggered self.getPartLCS() to fill the LCS list # find the old attachment Datum in the list of the Datums in the linked part... lcs_found = self.attLCSlist.findItems(old_attLCS, QtCore.Qt.MatchExactly) if not lcs_found: lcs_found = self.attLCSlist.findItems(old_attLCS + ' (', QtCore.Qt.MatchStartsWith) if lcs_found: # ... and select it self.attLCSlist.setCurrentItem(lcs_found[0])
def IsActive(self): # We only insert a link into an Asm4 Model if App.ActiveDocument and Asm4.getSelectedLink(): return True return False
def Activated(self): # This function is executed when the command is activated # initialise stuff # this is the App::Part where we'll put our App::Link self.asmPart = None self.origLink = None self.allParts = [] self.partsDoc = [] self.filterPartList.clear() self.partList.clear() self.linkNameInput.clear() # get the current active document to avoid errors if user changes tab self.activeDoc = App.ActiveDocument # an App::Part at the root of the document is selected, we insert the link there if Asm4.getSelectedRootPart(): self.asmPart = Asm4.getSelectedRootPart() # a link is selected, let's see if we can duplicate it elif Asm4.getSelectedLink(): selObj = Asm4.getSelectedLink() parent = selObj.getParentGeoFeatureGroup() # if the selectd link is in a root App::Part if parent.TypeId == 'App::Part' and parent.getParentGeoFeatureGroup( ) is None: self.asmPart = parent self.origLink = selObj elif Asm4.checkModel(): self.asmPart = self.activeDoc.getObject('Model') if self.asmPart is None: Asm4.warningBox('Please create an Assembly Model') return # Search for all App::Parts and PartDesign::Body in all open documents # Also store the document of the part for doc in App.listDocuments().values(): for obj in doc.findObjects("App::Part"): # we don't want to link to itself to the 'Model' object # other App::Part in the same document are OK # but only those at top level (not nested inside other containers) if obj != self.asmPart and obj.getParentGeoFeatureGroup( ) is None: self.allParts.append(obj) self.partsDoc.append(doc) for obj in doc.findObjects("PartDesign::Body"): # but only those at top level (not nested inside other containers) if obj.getParentGeoFeatureGroup() is None: self.allParts.append(obj) self.partsDoc.append(doc) # build the list for part in self.allParts: newItem = QtGui.QListWidgetItem() if part.Name == part.Label: partText = part.Name else: partText = part.Label + ' (' + part.Name + ')' newItem.setText(part.Document.Name + "#" + partText) newItem.setIcon(part.ViewObject.Icon) self.partList.addItem(newItem) # if an existing App::Link was selected if self.origLink: origPart = self.origLink.LinkedObject # try to find the original part of the selected link # MatchExactly, MatchContains, MatchEndsWith, MatchStartsWith ... origPartText = origPart.Document.Name + "#" + origPart.Label # if Label!=Name then the string still starts with Label partFound = self.partList.findItems(origPartText, QtCore.Qt.MatchStartsWith) if partFound: self.partList.setCurrentItem(partFound[0]) # set the proposed name to a duplicate of the original link name origName = self.origLink.Label # if the last character is a number, we increment this number lastChar = origName[-1] if lastChar.isnumeric(): rootName = origName[:-1] instanceNum = int(lastChar) while App.ActiveDocument.getObject(rootName + str(instanceNum)): instanceNum += 1 proposedLinkName = rootName + str(instanceNum) # else we append a _2 to the original name (Label) else: proposedLinkName = origName + '_2' self.linkNameInput.setText(proposedLinkName) # show the UI self.show()
def IsActive(self): # We only insert a link into an Asm4 Model if Asm4.checkModel() or Asm4.getSelectedRootPart( ) or Asm4.getSelectedLink(): return True return False
def IsActive(self): # Will handle LCSs only for the Assembly4 model #if Asm4.getSelectedLink() or Asm4.getModelSelected(): if Asm4.getSelectedLink() or Asm4.checkModel(): return True return False
def IsActive(self): # treats all container types : Body and Part if Asm4.getSelectedContainer() or Asm4.checkModel( ) or Asm4.getSelectedLink(): return True return False
def IsActive(self): # this works on Parts and Bodies, and links to such if Asm4.getSelectedLink() or Asm4.getSelectedContainer(): return(True) else: return(False)