def clicked(self, bt): if bt == QtGui.QDialogButtonBox.Ignore: # ask for confirmation before resetting everything msgName = Asm4.nameLabel(self.selectedDatum) # see whether the ExpressionEngine field is filled if self.selectedDatum.ExpressionEngine: # if yes, then ask for confirmation confirmed = Asm4.confirmBox( 'This command will release all attachments on ' + msgName + ' and set it to manual positioning in its current location.' ) # if not, then it's useless to bother the user else: confirmed = True if confirmed: self.selectedDatum.setExpression('Placement', None) self.finish()
def Activated(self): # check what we have selected selectedObj = self.checkSelection() if not selectedObj: return objName = selectedObj.Name objLabel = selectedObj.Label objType = selectedObj.TypeId # ask for confirmation before resetting everything confirmText = 'This command will release all attachments on '+Asm4.labelName(selectedObj) \ +' and set it to manual positioning in its current location.' if not Asm4.confirmBox(confirmText): # don't do anything return # the root Assembly4 Model # model = App.ActiveDocument.getObject('Model') model = Asm4.getAssembly() # handle object types differently # an App::Link if objType == 'App::Link': # unset the ExpressionEngine for the Placement selectedObj.setExpression('Placement', None) # reset Asm4 properties Asm4.makeAsmProperties(selectedObj, reset=True) # a datum object else: # reset Asm4 properties Asm4.makeAsmProperties(selectedObj, reset=True) # unset both Placements (who knows what confusion the user has done) selectedObj.setExpression('Placement', None) selectedObj.setExpression('AttachmentOffset', None) # if it's a datum object if objType == 'PartDesign::CoordinateSystem' or objType == 'PartDesign::Plane' or objType == 'PartDesign::Line' or objType == 'PartDesign::Point': # unset the MapMode; this actually keeps the MapMode parameters intact, # so it's easy for the user to re-enable it selectedObj.MapMode = 'Deactivated' # recompute the assembly model model.recompute(True)
def clicked(self, bt): if bt == QtGui.QDialogButtonBox.Ignore: # ask for confirmation before resetting everything msgName = Asm4.labelName(self.selectedFastener) # see whether the ExpressionEngine field is filled if self.old_EE: # if yes, then ask for confirmation confirmed = Asm4.confirmBox( 'This command will release all attachments on ' + msgName + ' and set it to manual positioning in its current location.' ) else: # if not, then it's useless to bother the user confirmed = True if confirmed: # unset the ExpressionEngine in the Placement self.selectedFastener.setExpression('Placement', None) # reset Asm4 properties Asm4.makeAsmProperties(self.selectedFastener, reset=True) self.finish()
def onDelete(self): selectedItems = self.configList.selectedItems() if len(selectedItems) == 1: confName = self.configList.currentItem().name conf = getConfig(confName) if isAsm4Config(conf): confirm = Asm4.confirmBox('This will delete configuration "' + confName + '"?') if confirm: App.ActiveDocument.removeObject(confName) else: FCC.PrintMessage('Configuration "' + confName + '" not touched\n') else: FCC.PrintMessage( 'Object "' + confName + '" is not a valid Assembly4 configuration, leaving untouched\n' ) # rescan configuration list self.initUI()
def Activated(self): # check that we have selected a Fastener from the Fastener WB selection = getSelectionFS() if selection is None: return # check that the fastener is an Asm4 fastener if not hasattr(selection, 'SolverId'): Asm4.makeAsmProperties(selection) # we only deal with Asm4 or empty types asmType = selection.SolverId if asmType == 'Placement::ExpressionEngine' or asmType == '': # now we should be safe, call the UI Gui.Control.showDialog(placeFastenerUI()) else: convert = Asm4.confirmBox( "This doesn't seem to be an Assembly4 Fastener, but I can convert it." ) if convert: Asm4.makeAsmProperties(selection, reset=True) # selection.AssemblyType = 'Part::Link' selection.SolverId = 'Placement::ExpressionEngine' Gui.Control.showDialog(placeFastenerUI()) return
def SaveConfiguration(confName, description): FCC.PrintMessage('Saving configuration to "' + confName + '"\n') #conf = getConfig(confName, 'Configurations') conf = getConfig(confName) if conf and isAsm4Config(conf): confirm = Asm4.confirmBox( 'This will overwrite existing configuration "' + confName + '"') if not confirm: FCC.PrintMessage('Cancel save of configuration "' + confName + '"\n') return else: setConfigDescription(conf, description) else: conf = createConfig(confName, description) assy = Asm4.getAssembly() link = Asm4.getSelectedLink() if link: SaveObject(conf, link) else: SaveSubObjects(conf, assy) conf.recompute(True)
def clicked(self, button): if button == QtGui.QDialogButtonBox.Apply: self.Apply() elif button == QtGui.QDialogButtonBox.Ignore: # ask for confirmation before resetting everything msgName = Asm4.labelName(self.selectedObj) # see whether the ExpressionEngine field is filled if self.selectedObj.ExpressionEngine : # if yes, then ask for confirmation confirmed = Asm4.confirmBox('This command will release all attachments on '+msgName+' and set it to manual positioning in its current location.') # if not, then it's useless to bother the user else: confirmed = True if confirmed: # unset the ExpressionEngine for the Placement self.selectedObj.setExpression('Placement', None) # reset the assembly properties Asm4.makeAsmProperties( self.selectedObj, reset=True ) # finish FCC.PrintMessage("Part is now manually placed\n") self.finish() else: FCC.PrintMessage("Part untouched\n") self.finish()
def Activated(self): (selDatum, selTree) = Asm4.getSelectionTree() # the selected datum is not deep enough if not selTree or len(selTree) < 3: message = selDatum.Name + ' is already at the top-level and cannot be imported' Asm4.warningBox(message) return # the root parent container is the first in the selection tree rootContainer = App.ActiveDocument.getObject(selTree[0]) selection = self.getSelectedDatums() # special case where 2 objects are selected in order to update the placement of the second one if len(selection) == 2 and selection[1].getParentGeoFeatureGroup( ) == rootContainer: confirm = False targetDatum = selection[1] # target datum is free if targetDatum.MapMode == 'Deactivated': message = 'This will superimpose ' + Asm4.labelName( targetDatum) + ' in ' + Asm4.labelName( rootContainer) + ' on:\n\n' for objName in selTree[1:-1]: message += '> ' + objName + '\n' message += '> ' + Asm4.labelName(selDatum) Asm4.warningBox(message) confirm = True # target datum is attached else: message = Asm4.labelName(targetDatum) + ' in ' + Asm4.labelName( rootContainer) + ' is already attached to some geometry. ' message += 'This will superimpose its Placement on:\n\n' for objName in selTree[1:-1]: message += '> ' + objName + '\n' message += '> ' + Asm4.labelName(selDatum) confirm = Asm4.confirmBox(message) if confirm: self.setupTargetDatum(targetDatum, self.getDatumExpression(selTree)) # hide initial datum selDatum.Visibility = False # select the newly created datum Gui.Selection.clearSelection() Gui.Selection.addSelection(App.ActiveDocument.Name, rootContainer.Name, targetDatum.Name + '.') # recompute assembly rootContainer.recompute(True) # Done with the special case, no need to continue with the normal process return # Single or Multiple selection(s) for regular case # Notify user that default names will be used and import all the objects proposedName = selTree[-2] + '_' + selDatum.Label if len(selection) == 1: message = 'Create a new ' + selDatum.TypeId + ' in ' + Asm4.labelName( rootContainer) + ' \nsuperimposed on:\n\n' for objName in selTree[1:]: message += '> ' + objName + '\n' message += '\nEnter name for this datum :' + ' ' * 40 userSpecifiedName, confirm = QtGui.QInputDialog.getText( None, 'Import Datum', message, text=proposedName) else: message = str( len(selection) ) + " selected datum objects will be imported into the root assembly\n" message += "with their default names such as:\n" message += proposedName confirm = Asm4.confirmBox(message) if confirm: for index in range(len(selection)): (selDatum, selTree) = Asm4.getSelectionTree(index) # create a new datum object if len(selection) == 1: proposedName = userSpecifiedName else: proposedName = selTree[-2] + '_' + selDatum.Label targetDatum = rootContainer.newObject(selDatum.TypeId, proposedName) targetDatum.Label = proposedName # apply existing view properties if applicable if hasattr(selDatum, 'ResizeMode') and selDatum.ResizeMode == 'Manual': targetDatum.ResizeMode = 'Manual' if hasattr(selDatum, 'Length'): targetDatum.Length = selDatum.Length if hasattr(selDatum, 'Width'): targetDatum.Width = selDatum.Width targetDatum.ViewObject.ShapeColor = selDatum.ViewObject.ShapeColor targetDatum.ViewObject.Transparency = selDatum.ViewObject.Transparency self.setupTargetDatum(targetDatum, self.getDatumExpression(selTree)) # hide initial datum selDatum.Visibility = False # select the last created datum Gui.Selection.clearSelection() Gui.Selection.addSelection(App.ActiveDocument.Name, rootContainer.Name, targetDatum.Name + '.') # recompute assembly rootContainer.recompute(True)
def Activated(self): # try with a regular App::Link selection = Asm4.getSelectedLink() # may-be an Asm4::VariantLink ? if selection is None: selection = Asm4.getSelectedVarLink() # if we found a valid link if selection is not None: # check that it's in the root assembly parent = selection.getParentGeoFeatureGroup() if parent and parent == Asm4.getAssembly(): # if it's a valid assembly and part if Asm4.isAsm4EE(selection): # BUGFIX: if the part was corrupted by Assembly4 v0.11.5: if hasattr(selection, 'MapMode'): Asm4.warningBox( "This Part has the Attachment extension, it can only be placed manually" ) else: # launch the UI in the task panel ui = placeLinkUI() Gui.Control.showDialog(ui) # else try to convert it else: convert = Asm4.confirmBox( "This Part wasn't assembled with this Assembly4 WorkBench, but I can convert it." ) if convert: Asm4.makeAsmProperties(selection, reset=True) # launch the UI in the task panel ui = placeLinkUI() Gui.Control.showDialog(ui) else: Asm4.warningBox('Please select a link in the assembly Model.') else: # or any part that has a Placement ? if len(Gui.Selection.getSelection()) == 1: selection = Gui.Selection.getSelection()[0] # object has a Placement property if hasattr(selection, 'Placement') and selection.getTypeIdOfProperty( 'Placement') == 'App::PropertyPlacement': # we don't want to mess with obects that are attached with the Attacher (MapMode) if hasattr(selection, 'MapMode'): FCC.PrintMessage( 'Object has MapMode property, you should use that\n' ) else: # check that it's in the root assembly parent = selection.getParentGeoFeatureGroup() if parent and parent == Asm4.getAssembly(): # is it's a virgin object, give it Asm4 properties if not hasattr(selection, 'SolverId'): Asm4.makeAsmProperties(selection) # if it's a valid assembly and part if Asm4.isAsm4EE(selection): # launch the UI in the task panel ui = placePartUI() Gui.Control.showDialog(ui) # else try to convert it else: convert = Asm4.confirmBox( "This Part wasn't assembled with this Assembly4 WorkBench, but I can convert it." ) if convert: Asm4.makeAsmProperties(selection, reset=True) # launch the UI in the task panel ui = placePartUI() Gui.Control.showDialog(ui) # the selected object doesn't belong to the root assembly else: Asm4.warningBox( 'Please select an object in the assembly Model.' ) return