def onCreateLink(self): # parse the selected items selectedPart = [] for selected in self.partList.selectedIndexes(): # get the selected part selectedPart = self.allParts[selected.row()] # get the name of the link (as it should appear in the tree) linkName = self.linkNameInput.text() # repair broken link if self.brokenLink and selectedPart: self.origLink.LinkedObject = selectedPart self.origLink.recompute() self.UI.close() # ... and launch the placement of the inserted part Gui.Selection.clearSelection() Gui.Selection.addSelection(self.activeDoc.Name, self.rootAssembly.Name, self.origLink.Name + '.') # ... but only if we're in an Asm4 Model if self.rootAssembly == Asm4.getAssembly(): Gui.runCommand('Asm4_placeLink') # only create link if there is a Part object and a name elif self.rootAssembly and selectedPart and linkName: # check that the current document had been saved # or that it's the same document as that of the selected part if App.ActiveDocument.FileName != '' or App.ActiveDocument == selectedPart.Document: # create the App::Link with the user-provided name #createdLink = self.activeDoc.getObject('Model').newObject( 'App::Link', linkName ) createdLink = self.rootAssembly.newObject( 'App::Link', linkName) # assign the user-selected selectedPart to it createdLink.LinkedObject = selectedPart # If the name was already chosen, and a UID was generated: if createdLink.Name != linkName: # we try to set the label to the chosen name createdLink.Label = linkName # add the Asm4 properties Asm4.makeAsmProperties(createdLink) createdLink.AssemblyType = "Part::Link" # update the link createdLink.recompute() # close the dialog UI... self.UI.close() # ... and launch the placement of the inserted part Gui.Selection.clearSelection() Gui.Selection.addSelection(self.activeDoc.Name, self.rootAssembly.Name, createdLink.Name + '.') # ... but only if we're in an Asm4 Model if self.rootAssembly == Asm4.getAssembly(): Gui.runCommand('Asm4_placeLink') else: Asm4.warningBox( 'The current document must be saved before inserting an external part' ) return # if still open, close the dialog UI self.UI.close()
def checkSelection(self): # if something is selected ... if Gui.Selection.getSelection(): selectedObj = Gui.Selection.getSelection()[0] # ... and it's an App::Part or an datum object selType = selectedObj.TypeId if selType in self.containers or selType in Asm4.datumTypes or selType == 'Sketcher::SketchObject': return (selectedObj) # or of nothing is selected ... elif Asm4.getAssembly(): # ... but there is as assembly: return Asm4.getAssembly() # if we're here it's because we didn't find a good reason to not be here return None
def Activated(self): (fstnr, axes) = self.selection if fstnr.Document: for axisData in axes: if len(axisData) > 3: # DocName/ModelName/AppLinkName/AxisName docName = axisData[0] doc = App.getDocument(docName) if doc: model = doc.getObject(axisData[1]) if model: objLink = model.getObject(axisData[2]) if objLink: obj = objLink.getLinkedObject() axis = obj.getObject(axisData[3]) if axis and axis.Document: newFstnr = Asm4.cloneObject(fstnr) Asm4.placeObjectToLCS( newFstnr, axisData[2], axis.Document.Name, axisData[3]) Gui.Selection.clearSelection() self.rootAssembly = Asm4.getAssembly() if rootAssembly: Gui.Selection.addSelection(fstnr.Document.Name, self.rootAssembly.Name, fstnr.Name + '.')
def IsActive(self): # if a spreadsheet in a Group called "Configuration" is selected if Asm4.getAssembly() and len(Gui.Selection.getSelection()) == 1: config = Gui.Selection.getSelection()[0] if getConfGroup() and isAsm4Config(config): return True return False
def Activated(self): rootAssembly = Asm4.getAssembly() # get the selected objects selEx = Gui.Selection.getSelectionEx("", 0)[0].SubElementNames (objName, dot, shape) = selEx[0].partition('.') # the first element should be the name of a child in the assembly if objName + '.' in rootAssembly.getSubObjects(): # get the object where the selected shapes are obj = App.ActiveDocument.getObject(objName) # this is a double-check, should always be true at this point if obj: shape = (shape, ) # we must remove the first name in each selEx element if len(selEx) > 1: # the first one (shape) has already been done for sel in selEx[1:]: (objName, dot, shp) = sel.partition('.') shape += (shp, ) # now create the SubShapeBinder binder = rootAssembly.newObject('PartDesign::SubShapeBinder', 'ShapeBinder') binder.Support = [(obj, shape)] binder.MakeFace = False binder.ViewObject.LineColor = (0., 1., 0.) binder.recompute()
def createConfig(name, description): group = getConfGroup() if not group: # create a group Configurations to store various config tables assy = Asm4.getAssembly() if assy: group = assy.newObject('App::DocumentObjectGroup', 'Configurations') else: FCC.PrintWarnin('No assembly container here, quitting\n') return # Create the document conf = group.newObject('Spreadsheet::Sheet', name) headerRow = str(int(OBJECTS_START_ROW) - 1) #conf.set(HEADER_CELL, 'Assembly4 configuration table') conf.set(HEADER_CELL, ASM4_CONFIG_TYPE) conf.set(DESCRIPTION_CELL, str(description)) conf.set(OBJECT_NAME_COL + headerRow, 'ObjectName') conf.set(OBJECT_VISIBLE_COL + headerRow, 'Visible') conf.set(OBJECT_ASM_TYPE_COL + headerRow, 'Assembly Type') conf.set(OFFSET_POS_X_COL + headerRow, 'Pos. X') conf.set(OFFSET_POS_Y_COL + headerRow, 'Pos. Y') conf.set(OFFSET_POS_Z_COL + headerRow, 'Pos. Z') conf.set(OFFSET_ROT_YAW_COL + headerRow, 'Rot. Yaw') conf.set(OFFSET_ROT_PITCH_COL + headerRow, 'Rot. Pitch') conf.set(OFFSET_ROT_ROLL_COL + headerRow, 'Rot. Roll') return conf
def Activated(self): # retrieve the Variables object self.Variables = App.ActiveDocument.getObject('Variables') # if it doesn't exist then create it (for older Asm4 documents) if not self.Variables: self.Variables = Asm4.createVariables() part = None # if an App::Part is selected: if checkPart(): part = checkPart() # if an Asm4 Model is present: elif Asm4.getAssembly(): part = Asm4.getAssembly() if part: part.addObject(self.Variables) #self.Variables = part.newObject('App::FeaturePython','Variables') #self.Variables.ViewObject.Proxy = Asm4.setCustomIcon(object,'Asm4_Variables.svg') # create the Variables in the document #else: #self.Variables = App.ActiveDocument.addObject('App::FeaturePython','Variables') #self.Variables.ViewObject.Proxy = Asm4.setCustomIcon(object,'Asm4_Variables.svg') # (re-)initialise the UI self.typeList.clear() self.varName.clear() self.varValue.setValue( 10.0 ) self.description.clear() self.UI.show() # get all supported Property types for prop in self.Variables.supportedProperties(): if prop in self.allowedProperties: # remove the leading 'App::Property' for clarity self.typeList.addItem(prop[13:]) # find the Float property # propFloat = self.typeList.findText( 'App::PropertyFloat' ) propFloat = self.typeList.findText( 'Float' ) # if not found if propFloat == -1: self.typeList.setCurrentIndex( 0 ) else: self.typeList.setCurrentIndex( propFloat ) # set focus on the variable name self.varName.setFocus()
def IsActive(self): # if an App::Link is selected, even a broken one if Gui.Selection.getSelection() and Gui.Selection.getSelection()[0].isDerivedFrom('App::Link'): return True # there is an assembly or a root App::Part is selected elif Asm4.getAssembly() or Asm4.getSelectedRootPart(): return True return False
def IsActive(self): # we only insert variant links into assemblies and root parts if Asm4.getAssembly() or Asm4.getSelectedRootPart(): return True # if an existing variant link is selected, we duplicate it if Asm4.getSelectedVarLink(): return True return False
def showHide(show): # reset processed links cache processedLinks = [] # if something is selected if Gui.Selection.hasSelection(): for sel in Gui.Selection.getSelection(): if sel.isDerivedFrom('App::Link'): showChildLCSs(sel, show, processedLinks) elif sel.TypeId in Asm4.containerTypes: for objName in sel.getSubObjects(1): showChildLCSs(sel.getSubObject(objName, 1), show, processedLinks) # if not, apply it to the assembly elif Asm4.getAssembly(): asm = Asm4.getAssembly() for objName in asm.getSubObjects(1): showChildLCSs(asm.getSubObject(objName, 1), show, processedLinks)
def restoreConfiguration(confName): FCC.PrintMessage('Restoring configuration "' + confName + '"\n') #doc = getConfig(confName, 'Configurations') conf = getConfig(confName) assy = Asm4.getAssembly() link = Asm4.getSelectedLink() if link: restoreObject(conf, link) else: restoreSubObjects(conf, assy) App.ActiveDocument.recompute()
def checkSelection(self): selectedObj = None # check that there is an App::Part called 'Model' # a standard App::Part would also do, but then more error checks are necessary # if App.ActiveDocument.getObject('Model') and App.ActiveDocument.getObject('Model').TypeId=='App::Part' : if Asm4.getAssembly() and len(Gui.Selection.getSelection()) == 1: # set the (first) selected object as global variable selection = Gui.Selection.getSelection()[0] if Asm4.isAsm4EE(selection) and selection.SolverId != '': selectedObj = selection # now we should be safe return selectedObj
def Activated(self): # grab the Variables container (just do it always, this prevents problems with newly opened docs) self.ActiveDocument = App.ActiveDocument self.Variables = self.AnimatedDocument.getObject( 'Variables') if self.AnimatedDocument else None # the root assembly in the current document self.rootAssembly = Asm4.getAssembly() self.updateDocList() self.updateVarList() # in case the dialog is newly opened, register for changes of the selected document if not self.UI.isVisible(): self.MDIArea.subWindowActivated.connect(self.onDocChanged) self.UI.show()
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 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 __init__(self): # self.base = QtGui.QWidget() # self.form = self.base self.form = QtGui.QWidget() self.form.setWindowIcon(QtGui.QIcon(iconFile)) self.form.setWindowTitle('Attach a Fastener in the assembly') # 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.rootAssembly = Asm4.getAssembly() # has been checked before calling self.selectedFastener = getSelectionFS() # check where the fastener was attached to (self.old_Parent, separator, self.old_parentLCS) = self.selectedFastener.AttachedTo.partition('#') # get and store the Placement's current ExpressionEngine: self.old_EE = Asm4.placementEE(self.selectedFastener.ExpressionEngine) if hasattr(self.selectedFastener, 'AttachmentOffset'): self.old_AO = self.selectedFastener.AttachmentOffset else: self.old_AO = None # Now we can draw the UI self.drawUI() self.initUI() # now self.parentList and self.parentTable are available # find all the linked parts in the assembly for obj in self.activeDoc.findObjects("App::Link"): if self.rootAssembly.getObject(obj.Name) is not None and hasattr( obj.LinkedObject, 'isDerivedFrom'): linkedObj = obj.LinkedObject FCC.PrintMessage("found link to " + linkedObj.Name) if linkedObj.isDerivedFrom( 'App::Part') or linkedObj.isDerivedFrom( 'PartDesign::Body'): # add to the object table holding the objects ... self.parentTable.append(obj) # ... and add to the drop-down combo box with the assembly tree's parts objIcon = linkedObj.ViewObject.Icon objText = Asm4.labelName(obj) self.parentList.addItem(objIcon, objText, obj) # decode the old ExpressionEngine # if the decode is unsuccessful, old_Expression is set to False # and old_attPart and old_attLCS are set to 'None' old_Parent = '' old_parentPart = '' old_parentLCS = '' if self.old_EE and self.old_Parent: (old_Parent, old_parentPart, old_parentLCS) = self.splitExpressionFastener( self.old_EE, self.old_Parent) # find the oldPart in the part list... parent_index = 1 if old_Parent == 'Parent Assembly': parent_found = True else: parent_found = False for item in self.parentTable[1:]: if item.Name == old_Parent: parent_found = True break else: 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 oldLCS in the list of LCS of the linked part... lcs_found = [] lcs_found = self.attLCSlist.findItems(old_parentLCS, QtCore.Qt.MatchExactly) # may-be it was renamed, see if we can find it as (name) if not lcs_found: lcs_found = self.attLCSlist.findItems('(' + old_parentLCS + ')', QtCore.Qt.MatchContains) if lcs_found: # ... and select it self.attLCSlist.setCurrentItem(lcs_found[0]) Gui.Selection.addObserver(self, 0)
def IsActive(self): if Asm4.getAssembly() and getSelectionFS(): return True return False
def IsActive(self): # is there an active document ? if Asm4.getAssembly() and App.ActiveDocument.getObject('Variables'): return True return False
def IsActive(self): # if something is selected or an Asm4 assembly present if Gui.Selection.hasSelection() or Asm4.getAssembly(): return True return False
def IsActive(self): # return self.checkModel() if Asm4.getAssembly() is None: return False else: return True
def __init__(self): # remove selectionFilter self.selectionFilterStatus = selectionFilter.observerStatus() selectionFilter.observerDisable() # get the current active document to avoid errors if user changes tab self.activeDoc = App.ActiveDocument # we have checked before that all this is correct selection = Asm4.getSelectedLink() if selection is None: selection = Asm4.getSelectedVarLink() self.selectedObj = selection #self.rootAssembly = self.selectedObj.getParentGeoFeatureGroup() self.rootAssembly = Asm4.getAssembly() # has been checked before, this is for security only if Asm4.isAsm4EE(self.selectedObj): # get the old values self.old_AO = self.selectedObj.AttachmentOffset self.old_linkLCS = self.selectedObj.AttachedBy[1:] else: # this shouldn't happen FCC.PrintWarning("WARNING : unsupported Assembly/Solver/Part combination, you shouldn't be seeing this\n") Asm4.makeAsmProperties(self.selectedObj) self.old_AO = [] self.old_linkLCS = '' # define the GUI # draw the GUI, objects are defined later down # self.UI = QtGui.QWidget() # self.form = self.UI self.form = QtGui.QWidget() iconFile = os.path.join( Asm4.iconPath , 'Place_Link.svg') self.form.setWindowIcon(QtGui.QIcon( iconFile )) self.form.setWindowTitle('Place linked Part') self.drawUI(self.form) #save original AttachmentOffset of linked part self.old_LinkAttachmentOffset = self.selectedObj.AttachmentOffset self.old_LinkRotation = self.selectedObj.AttachmentOffset.Rotation self.old_LinkPosition = self.selectedObj.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.selectedObj.ViewObject.OverrideMaterial self.old_DrawStyle = self.selectedObj.ViewObject.DrawStyle self.old_LineWidth = self.selectedObj.ViewObject.LineWidth self.old_DiffuseColor = self.selectedObj.ViewObject.ShapeMaterial.DiffuseColor self.old_Transparency = self.selectedObj.ViewObject.ShapeMaterial.Transparency # set new view properties self.selectedObj.ViewObject.OverrideMaterial = True self.selectedObj.ViewObject.DrawStyle = DrawStyle self.selectedObj.ViewObject.LineWidth = LineWidth self.selectedObj.ViewObject.ShapeMaterial.DiffuseColor = DiffuseColor self.selectedObj.ViewObject.ShapeMaterial.Transparency = Transparency # get the old values self.old_EE = '' old_Parent = '' old_ParentPart = '' old_attLCS = '' constrName = '' linkedDoc = '' old_linkLCS = '' # get and store the current expression engine: self.old_EE = Asm4.placementEE(self.selectedObj.ExpressionEngine) # decode the old ExpressionEngine # if the decode is unsuccessful, old_Expression is set to False and the other things are set to 'None' (self.old_Parent, separator, self.old_parentLCS) = self.selectedObj.AttachedTo.partition('#') ( old_Parent, old_attLCS, old_linkLCS ) = self.splitExpressionLink( self.old_EE, self.old_Parent ) # sometimes, the object is in << >> which is an error by FreeCAD, # because that's reserved for labels, but we still look for it if len(old_attLCS)>4 and old_attLCS[:2]=='<<' and old_attLCS[-2:]=='>>': old_attLCS = old_attLCS[2:-2] if len(old_linkLCS)>4 and old_linkLCS[:2]=='<<' and old_linkLCS[-2:]=='>>': old_linkLCS = old_linkLCS[2:-2] # 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 obj in self.activeDoc.findObjects("App::Link"): if self.rootAssembly.getObject(obj.Name) is not None and hasattr(obj.LinkedObject,'isDerivedFrom'): linkedObj = obj.LinkedObject if linkedObj.isDerivedFrom('App::Part') or linkedObj.isDerivedFrom('PartDesign::Body'): # ... except if it's the selected link itself if obj != self.selectedObj: self.parentTable.append( obj ) # add to the drop-down combo box with the assembly tree's parts objIcon = linkedObj.ViewObject.Icon objText = Asm4.labelName(obj) self.parentList.addItem( objIcon, objText, obj) # find all the LCS in the selected link self.partLCStable = Asm4.getPartLCS( self.selectedObj.LinkedObject ) # build the list self.partLCSlist.clear() for lcs in self.partLCStable: newItem = QtGui.QListWidgetItem() newItem.setText(Asm4.labelName(lcs)) newItem.setIcon( lcs.ViewObject.Icon ) self.partLCSlist.addItem(newItem) # find the old LCS in the list of LCS of the linked part... # MatchExactly, MatchContains, MatchEndsWith ... # find with Name ... lcs_found = self.partLCSlist.findItems( old_linkLCS, QtCore.Qt.MatchExactly ) # ... or with (Name) if not lcs_found: lcs_found = self.partLCSlist.findItems( '('+old_linkLCS+')', QtCore.Qt.MatchEndsWith ) 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.MatchEndsWith ) if lcs_found: # ... and select it self.attLCSlist.setCurrentItem( lcs_found[0] ) # selection observer to detect selection of LCS in the 3D window and tree Gui.Selection.addObserver(self, 0)
def IsActive(self): # Will handle LCSs only for the Assembly4 model #if Asm4.getSelectedLink() or Asm4.getModelSelected(): if Asm4.getSelectedLink() or Asm4.getAssembly(): return True return False
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
def Activated(self): config = Gui.Selection.getSelection()[0] restoreConfiguration(config.Name) Gui.Selection.clearSelection() Gui.Selection.addSelection(Asm4.getAssembly())
def Activated(self): # check that we have somewhere to put our stuff selectedObj = self.checkSelection() # default name increments the datum type's end numeral proposedName = Asm4.nextInstance(self.datumName, startAtOne=True) # check whether we have selected a container if selectedObj.TypeId in self.containers: parentContainer = selectedObj # if a datum object is selected elif selectedObj.TypeId in Asm4.datumTypes or selectedObj.TypeId == 'Sketcher::SketchObject': # see whether it's in a container parent = selectedObj.getParentGeoFeatureGroup() if parent.TypeId in self.containers: parentContainer = parent # if there is an assembly elif Asm4.getAssembly(): parentContainer = Asm4.getAssembly() # something went wrong else: Asm4.warningBox("I can't create a " + self.datumType + " with the current selections") # check whether there is already a similar datum, and increment the instance number # instanceNum = 1 #while App.ActiveDocument.getObject( self.datumName+'_'+str(instanceNum) ): # instanceNum += 1 #datumName = self.datumName+'_'+str(instanceNum) if parentContainer: # input dialog to ask the user the name of the Sketch: #proposedName = Asm4.nextInstance( self.datumName + '_' + selectedObj.Label, startAtOne=True ) text, ok = QtGui.QInputDialog.getText( None, 'Create new ' + self.datumName, 'Enter ' + self.datumName + ' name :' + ' ' * 40, text=proposedName) if ok and text: # App.activeDocument().getObject('Model').newObject( 'Sketcher::SketchObject', text ) createdDatum = App.ActiveDocument.addObject( self.datumType, text) parentContainer.addObject(createdDatum) createdDatum.Label = text # automatic resizing of datum Plane sucks, so we set it to manual if self.datumType == 'PartDesign::Plane': createdDatum.ResizeMode = 'Manual' createdDatum.Length = 100 createdDatum.Width = 100 elif self.datumType == 'PartDesign::Line': createdDatum.ResizeMode = 'Manual' createdDatum.Length = 200 # if color or transparency is specified for this datum type if self.datumColor: Gui.ActiveDocument.getObject( createdDatum.Name).ShapeColor = self.datumColor if self.datumAlpha: Gui.ActiveDocument.getObject( createdDatum.Name).Transparency = self.datumAlpha # highlight the created datum object Gui.Selection.clearSelection() Gui.Selection.addSelection(App.ActiveDocument.Name, parentContainer.Name, createdDatum.Name + '.') Gui.runCommand('Part_EditAttachment')
def IsActive(self): # is there an active document ? if Asm4.getAssembly(): return True return False
def IsActive(self): self.selection = self.getSelectedAxes() if Asm4.getAssembly() and self.selection: return True return False
def Activated(self): # This function is executed when the command is activated self.UI = QtGui.QDialog() self.drawUI() # initialise stuff self.activeDoc = App.ActiveDocument self.rootAssembly = None self.origLink = None self.brokenLink = False self.allParts = [] self.partsDoc = [] self.filterPartList.clear() self.partList.clear() self.linkNameInput.clear() # if an Asm4 Assembly is present, that's where we put the variant link if Asm4.getAssembly(): self.rootAssembly = Asm4.getAssembly() # an App::Part at the root of the document is selected, we insert the link there elif Asm4.getSelectedRootPart(): self.rootAssembly = Asm4.getSelectedRootPart() # if a variant link is selected, we see if we can duplicate it if Asm4.getSelectedVarLink(): selObj = Asm4.getSelectedVarLink() parent = selObj.getParentGeoFeatureGroup() # if the selected link is in a root App::Part if parent.TypeId == 'App::Part' and parent.getParentGeoFeatureGroup() is None: self.rootAssembly = parent self.origLink = selObj self.origPart = selObj.SourceObject ''' # if a broken link is selected elif len(Gui.Selection.getSelection())==1 : selObj = Gui.Selection.getSelection()[0] if selObj.isDerivedFrom('App::Link') and selObj.LinkedObject is None: parent = selObj.getParentGeoFeatureGroup() # if the selected (broken) link is in a root App::Part if parent.TypeId == 'App::Part' and parent.getParentGeoFeatureGroup() is None: self.brokenLink = True self.rootAssembly = parent self.origLink = selObj self.UI.setWindowTitle('Re-link broken link') self.insertButton.setText('Replace') self.linkNameInput.setText(Asm4.labelName(selObj)) self.linkNameInput.setEnabled(False) ''' if self.rootAssembly is None: Asm4.warningBox( 'Please create an Assembly' ) return # Search for all App::Parts having a "Variables" property container in all open documents # Also store the document of the part for doc in App.listDocuments().values(): # don't consider temporary documents if not doc.Temporary: 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.rootAssembly and obj.getParentGeoFeatureGroup() is None: # and only those that have a Variables property container variables = obj.getObject('Variables') if hasattr(variables,'Type') and variables.Type=='App::PropertyContainer': self.allParts.append( obj ) self.partsDoc.append( doc ) # build the list for part in self.allParts: newItem = QtGui.QListWidgetItem() newItem.setText( part.Document.Name +"#"+ Asm4.labelName(part) ) newItem.setIcon(part.ViewObject.Icon) self.partList.addItem(newItem) # if an existing valid App::Link was selected if self.origLink and not self.brokenLink: origPart = self.origLink.SourceObject # try to find the original part of the selected link origPartText = origPart.Document.Name +"#"+ Asm4.labelName(origPart) # MatchExactly, MatchContains, MatchEndsWith, MatchStartsWith ... partFound = self.partList.findItems( origPartText, QtCore.Qt.MatchExactly ) if partFound: self.partList.setCurrentItem(partFound[0]) # self.onItemClicked(partFound[0]) # if the last character is a number, we increment this number origName = self.origLink.Label lastChar = origName[-1] if lastChar.isnumeric(): (rootName,sep,num) = origName.rpartition('_') proposedLinkName = Asm4.nextInstance(rootName,startAtOne=True) # else we take the next instance else: proposedLinkName = Asm4.nextInstance(origName) # set the proposed name in the entry field if not self.brokenLink: self.linkNameInput.setText( proposedLinkName ) # show the UI self.UI.show()
def IsActive(self): # only do this for assembly objects and all selected shapes must be in the same part if Asm4.getAssembly() and len(Gui.Selection.getSelection()) == 1: return True else: return False