def Activated(self): # check whether there is already Model in the document assy = App.ActiveDocument.getObject('Assembly') if assy: if assy.TypeId == 'App::Part': Asm4.warningBox( "This document already contains a valid Assembly, please use it" ) # set the Type to Assembly assy.Type = 'Assembly' else: message = "This document already contains another FreeCAD object called \"Assembly\", " message += "but it's of type \"" + assy.TypeId + "\", unsuitable for an assembly. I can\'t proceed." Asm4.warningBox(message) # abort return # there is no object called "Assembly" # create a group 'Parts' to hold all parts in the assembly document (if any) # must be done before creating the assembly partsGroup = App.ActiveDocument.getObject('Parts') if partsGroup is None: partsGroup = App.ActiveDocument.addObject( 'App::DocumentObjectGroup', 'Parts') # create a new App::Part called 'Assembly' assembly = App.ActiveDocument.addObject('App::Part', 'Assembly') # set the type as a "proof" that it's an Assembly assembly.Type = 'Assembly' assembly.addProperty('App::PropertyString', 'AssemblyType', 'Assembly') assembly.AssemblyType = 'Part::Link' # add an LCS at the root of the Model, and attach it to the 'Origin' lcs0 = assembly.newObject('PartDesign::CoordinateSystem', 'LCS_Origin') lcs0.Support = [(assembly.Origin.OriginFeatures[0], '')] lcs0.MapMode = 'ObjectXY' lcs0.MapReversed = False # create an object Variables to hold variables to be used in this document assembly.addObject(Asm4.createVariables()) # create a group Constraints to store future solver constraints there assembly.newObject('App::DocumentObjectGroup', 'Constraints') # create a group Configurations to store future solver constraints there assembly.newObject('App::DocumentObjectGroup', 'Configurations') # move existing parts and bodies at the document root to the Parts group # not nested inside other parts, to keep hierarchy if partsGroup.TypeId == 'App::DocumentObjectGroup': for obj in App.ActiveDocument.Objects: if obj.TypeId in Asm4.containerTypes and obj.Name != 'Assembly' and obj.getParentGeoFeatureGroup( ) is None: partsGroup.addObject(obj) else: Asm4.warningBox( 'There seems to already be a Parts object, you might get unexpected behaviour' ) # recompute to get rid of the small overlays assembly.recompute() App.ActiveDocument.recompute()
def Activated(self): # get the current active document to avoid errors if user changes tab self.activeDoc = App.activeDocument() # check whether there is already Model in the document if not self.checkModel(): # create a group 'Parts' to hold all parts in the assembly document (if any) # must be done before creating the Asm4 Model partsGroup = self.activeDoc.getObject('Parts') if partsGroup is None: partsGroup = self.activeDoc.addObject( 'App::DocumentObjectGroup', 'Parts') # create a new App::Part called 'Model' assembly = self.activeDoc.addObject('App::Part', 'Model') # set the type as a "proof" that it's an Assembly4 Model assembly.Type = 'Assembly' assembly.addProperty('App::PropertyString', 'AssemblyType', 'Assembly') assembly.AssemblyType = 'Part::Link' # add an LCS at the root of the Model, and attach it to the 'Origin' lcs0 = assembly.newObject('PartDesign::CoordinateSystem', 'LCS_Origin') lcs0.Support = [(assembly.Origin.OriginFeatures[0], '')] lcs0.MapMode = 'ObjectXY' lcs0.MapReversed = False # create a group Constraints to store future solver constraints there assembly.newObject('App::DocumentObjectGroup', 'Constraints') # create an object Variables to hold variables to be used in this document assembly.addObject(Asm4.createVariables()) # create a group Configurations to store future solver constraints there assembly.newObject('App::DocumentObjectGroup', 'Configurations') # move existing parts and bodies at the document root to the Parts group # not nested inside other parts, to keep hierarchy if partsGroup.TypeId == 'App::DocumentObjectGroup': for obj in self.activeDoc.Objects: if obj.TypeId in Asm4.containerTypes and obj.Name != 'Model' and obj.getParentGeoFeatureGroup( ) is None: partsGroup.addObject(obj) else: Asm4.warningBox( 'There seems to already be a Parts object, you might get unexpected behaviour' ) # recompute to get rid of the small overlays assembly.recompute() self.activeDoc.recompute()
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()