def Activated(self): from DraftTools import translate FreeCAD.ActiveDocument.openTransaction(str(translate("Spreadsheet","Create Spreadsheet"))) FreeCADGui.doCommand("import Spreadsheet") FreeCADGui.doCommand("Spreadsheet.makeSpreadsheet()") FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute()
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create Analysis") FreeCADGui.addModule("FemGui") FreeCADGui.doCommand("App.activeDocument().addObject('Fem::FemAnalysis','MachineDistortion')") FreeCADGui.doCommand("FemGui.setActiveAnalysis(App.activeDocument().ActiveObject)") FreeCAD.ActiveDocument.commitTransaction() FreeCADGui.Selection.clearSelection()
def Activated(self): # check that the selection contains exactly what we want selection = FreeCADGui.Selection.getSelection() if len(selection) != 1: FreeCAD.Console.PrintError(translate("Path_Dressup","Please select one path object\n")) return if not selection[0].isDerivedFrom("Path::Feature"): FreeCAD.Console.PrintError(translate("Path_Dressup","The selected object is not a path\n")) return if selection[0].isDerivedFrom("Path::FeatureCompoundPython"): FreeCAD.Console.PrintError(translate("Path_Dressup", "Please select a Path object")) return # everything ok! FreeCAD.ActiveDocument.openTransaction(translate("Path_Dressup","Create Dress-up")) FreeCADGui.addModule("PathScripts.PathDressup") FreeCADGui.addModule("PathScripts.PathUtils") FreeCADGui.doCommand('obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython","Dressup")') FreeCADGui.doCommand('PathScripts.PathDressup.ObjectDressup(obj)') FreeCADGui.doCommand('obj.Base = FreeCAD.ActiveDocument.' + selection[0].Name) FreeCADGui.doCommand('PathScripts.PathDressup.ViewProviderDressup(obj.ViewObject)') FreeCADGui.doCommand('PathScripts.PathUtils.addToProject(obj)') FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute()
def Activated(self): sel = FreeCADGui.Selection.getSelection() if len(sel) == 1 and sel[0].isDerivedFrom("App::MaterialObjectPython"): lin_mat_obj = sel[0] # check if an nonlinear material exists which is based on the selected material already allow_nonlinear_material = True for o in FreeCAD.ActiveDocument.Objects: if hasattr(o, "Proxy") and o.Proxy is not None and o.Proxy.Type == "FemMaterialMechanicalNonlinear" and o.LinearBaseMaterial == lin_mat_obj: FreeCAD.Console.PrintError(o.Name + ' is based on the selected material: ' + lin_mat_obj.Name + '. Only one nonlinear object for each material allowed.\n') allow_nonlinear_material = False break if allow_nonlinear_material: string_lin_mat_obj = "FreeCAD.ActiveDocument.getObject('" + lin_mat_obj.Name + "')" command_to_run = "FemGui.getActiveAnalysis().addObject(ObjectsFem.makeMaterialMechanicalNonlinear(FreeCAD.ActiveDocument, " + string_lin_mat_obj + "))" FreeCAD.ActiveDocument.openTransaction("Create FemMaterialMechanicalNonlinear") FreeCADGui.addModule("ObjectsFem") FreeCADGui.doCommand(command_to_run) # set some property of the solver to nonlinear (only if one solver is available and if this solver is a CalculiX solver): # nonlinear material # nonlinear geometry --> its is triggered anyway https://forum.freecadweb.org/viewtopic.php?f=18&t=23101&p=180489#p180489 solver_object = None for m in FemGui.getActiveAnalysis().Group: if m.isDerivedFrom('Fem::FemSolverObjectPython'): if not solver_object: solver_object = m else: # we do not change attributes if we have more than one solver, since we do not know which one to take solver_object = None break if solver_object and solver_object.SolverType == 'FemSolverCalculix': solver_object.MaterialNonlinearity = "nonlinear" solver_object.GeometricalNonlinearity = "nonlinear"
def Activated(self): sel = FreeCADGui.Selection.getSelectionEx() if sel: sel = sel[0] obj = sel.Object FreeCADGui.Control.closeDialog() if sel.HasSubObjects: if "Face" in sel.SubElementNames[0]: idx = int(sel.SubElementNames[0][4:]) FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Roof")) FreeCADGui.addModule("Arch") FreeCADGui.doCommand("Arch.makeRoof(FreeCAD.ActiveDocument."+obj.Name+","+str(idx)+")") FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() return if obj.isDerivedFrom("Part::Feature"): if obj.Shape.Wires: FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Roof")) FreeCADGui.addModule("Arch") FreeCADGui.doCommand("Arch.makeRoof(FreeCAD.ActiveDocument."+obj.Name+")") FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() return else: FreeCAD.Console.PrintMessage(translate("Arch","Unable to create a roof")) else: FreeCAD.Console.PrintMessage(translate("Arch","Please select a base object\n")) FreeCADGui.Control.showDialog(ArchComponent.SelectionTaskPanel()) FreeCAD.ArchObserver = ArchComponent.ArchSelectionObserver(nextCommand="Arch_Roof") FreeCADGui.Selection.addObserver(FreeCAD.ArchObserver)
def Activated(self): p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch") self.Length = p.GetFloat("PanelLength",1000) self.Width = p.GetFloat("PanelWidth",1000) self.Thickness = p.GetFloat("PanelThickness",10) self.Profile = None self.continueCmd = False self.rotated = False self.DECIMALS = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").GetInt("Decimals",2) self.FORMAT = "%." + str(self.DECIMALS) + "f mm" sel = FreeCADGui.Selection.getSelection() if sel: if len(sel) == 1: if Draft.getType(sel[0]) == "Panel": return FreeCAD.ActiveDocument.openTransaction(str(translate("Arch","Create Panel"))) FreeCADGui.addModule("Arch") for obj in sel: FreeCADGui.doCommand("Arch.makePanel(FreeCAD.ActiveDocument." + obj.Name + ",thickness=" + str(self.Thickness) + ")") FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() return # interactive mode if hasattr(FreeCAD,"DraftWorkingPlane"): FreeCAD.DraftWorkingPlane.setup() import DraftTrackers self.points = [] self.tracker = DraftTrackers.boxTracker() self.tracker.width(self.Width) self.tracker.height(self.Thickness) self.tracker.length(self.Length) self.tracker.on() FreeCADGui.Snapper.getPoint(callback=self.getPoint,movecallback=self.update,extradlg=self.taskbox())
def Activated(self): walls = FreeCADGui.Selection.getSelection() if len(walls) == 1: if Draft.getType(walls[0]) == "Wall": ostr = "FreeCAD.ActiveDocument."+ walls[0].Name ok = False for o in walls[0].Additions: if Draft.getType(o) == "Wall": ostr += ",FreeCAD.ActiveDocument." + o.Name ok = True if ok: FreeCAD.ActiveDocument.openTransaction(translate("Arch","Merge Wall")) FreeCADGui.addModule("Arch") FreeCADGui.doCommand("Arch.joinWalls(["+ostr+"],delete=True)") FreeCAD.ActiveDocument.commitTransaction() return else: FreeCAD.Console.PrintWarning(translate("Arch","The selected wall contains no subwall to merge")) return else: FreeCAD.Console.PrintWarning(translate("Arch","Please select only wall objects")) return for w in walls: if Draft.getType(w) != "Wall": FreeCAD.Console.PrintMessage(translate("Arch","Please select only wall objects")) return FreeCAD.ActiveDocument.openTransaction(translate("Arch","Merge Walls")) FreeCADGui.addModule("Arch") FreeCADGui.doCommand("Arch.joinWalls(FreeCADGui.Selection.getSelection(),delete=True)") FreeCAD.ActiveDocument.commitTransaction()
def Activated(self): string_lin_mat_obj = "FreeCAD.ActiveDocument.getObject('" + self.selobj.Name + "')" command_to_run = "FemGui.getActiveAnalysis().addObject(ObjectsFem.makeMaterialMechanicalNonlinear(FreeCAD.ActiveDocument, " + string_lin_mat_obj + "))" FreeCAD.ActiveDocument.openTransaction("Create FemMaterialMechanicalNonlinear") FreeCADGui.addModule("ObjectsFem") FreeCADGui.doCommand(command_to_run) # set some property of the solver to nonlinear (only if one solver is available and if this solver is a CalculiX solver): # nonlinear material # nonlinear geometry --> it is triggered anyway https://forum.freecadweb.org/viewtopic.php?f=18&t=23101&p=180489#p180489 solver_object = None for m in self.active_analysis.Group: if m.isDerivedFrom('Fem::FemSolverObjectPython'): if not solver_object: solver_object = m else: # we do not change attributes if we have more than one solver, since we do not know which one to take solver_object = None break # set solver attribute for nonlinearity for ccxtools CalculiX solver or new frame work CalculiX solver if hasattr(solver_object, "Proxy") and (solver_object.Proxy.Type == 'Fem::FemSolverCalculixCcxTools' or solver_object.Proxy.Type == 'Fem::FemSolverObjectCalculix'): print('Set MaterialNonlinearity and GeometricalNonlinearity to nonlinear for ' + solver_object.Label) solver_object.MaterialNonlinearity = "nonlinear" solver_object.GeometricalNonlinearity = "nonlinear" FreeCADGui.Selection.clearSelection() FreeCAD.ActiveDocument.recompute()
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create FemMeshRegion") FreeCADGui.addModule("ObjectsFem") FreeCADGui.doCommand("ObjectsFem.makeMeshRegion(FreeCAD.ActiveDocument, FreeCAD.ActiveDocument." + self.selobj.Name + ")") FreeCADGui.doCommand("FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)") FreeCADGui.Selection.clearSelection() FreeCAD.ActiveDocument.recompute()
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create FemConstraintInitialFlowVelocity") FreeCADGui.addModule("ObjectsFem") FreeCADGui.doCommand("FemGui.getActiveAnalysis().addObject(ObjectsFem.makeConstraintInitialFlowVelocity(FreeCAD.ActiveDocument))") FreeCADGui.doCommand("FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)") FreeCADGui.Selection.clearSelection() FreeCAD.ActiveDocument.recompute()
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create FemElementRotation1D") FreeCADGui.addModule("ObjectsFem") FreeCADGui.doCommand("FemGui.getActiveAnalysis().addObject(ObjectsFem.makeElementRotation1D(FreeCAD.ActiveDocument))") FreeCADGui.doCommand("FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)") FreeCADGui.Selection.clearSelection() FreeCAD.ActiveDocument.recompute()
def cmdCreateXORFeature(name): """cmdCreateXORFeature(name): implementation of GUI command to create XOR feature (GFA). Mode can be "Standard", "Split", or "CompSolid".""" sel = FreeCADGui.Selection.getSelectionEx() FreeCAD.ActiveDocument.openTransaction("Create Boolean XOR") FreeCADGui.addModule("BOPTools.SplitFeatures") FreeCADGui.doCommand("j = BOPTools.SplitFeatures.makeXOR(name= '{name}')".format(name= name)) FreeCADGui.doCommand("j.Objects = {sel}".format( sel= "[" + ", ".join(["App.ActiveDocument."+so.Object.Name for so in sel]) + "]" )) try: FreeCADGui.doCommand("j.Proxy.execute(j)") FreeCADGui.doCommand("j.purgeTouched()") except Exception as err: mb = QtGui.QMessageBox() mb.setIcon(mb.Icon.Warning) mb.setText(_translate("Part_SplitFeatures","Computing the result failed with an error: \n\n{err}\n\nClick 'Continue' to create the feature anyway, or 'Abort' to cancel.", None) .format(err= err.message)) mb.setWindowTitle(_translate("Part_SplitFeatures","Bad selection", None)) btnAbort = mb.addButton(QtGui.QMessageBox.StandardButton.Abort) btnOK = mb.addButton(_translate("Part_SplitFeatures","Continue",None), QtGui.QMessageBox.ButtonRole.ActionRole) mb.setDefaultButton(btnOK) mb.exec_() if mb.clickedButton() is btnAbort: FreeCAD.ActiveDocument.abortTransaction() return FreeCADGui.doCommand("for obj in j.ViewObject.Proxy.claimChildren():\n" " obj.ViewObject.hide()") FreeCAD.ActiveDocument.commitTransaction()
def Activated(self): sel = FreeCADGui.Selection.getSelection() if len(sel) == 1 and sel[0].isDerivedFrom("App::MaterialObjectPython"): lin_mat_obj = sel[0] # check if an nonlinear material exists which is based on the selected material already allow_nonlinear_material = True for o in FreeCAD.ActiveDocument.Objects: if hasattr(o, "Proxy") and o.Proxy is not None and o.Proxy.Type == "FemMaterialMechanicalNonlinear" and o.LinearBaseMaterial == lin_mat_obj: FreeCAD.Console.PrintError(o.Name + ' is based on the selected material: ' + lin_mat_obj.Name + '. Only one nonlinear object for each material allowed.\n') allow_nonlinear_material = False break if allow_nonlinear_material: string_lin_mat_obj = "App.ActiveDocument.getObject('" + lin_mat_obj.Name + "')" command_to_run = "FemGui.getActiveAnalysis().Member = FemGui.getActiveAnalysis().Member + [FemMaterialMechanicalNonlinear.makeFemMaterialMechanicalNonlinear(" + string_lin_mat_obj + ")]" FreeCAD.ActiveDocument.openTransaction("Create FemMaterialMechanicalNonlinear") FreeCADGui.addModule("FemMaterialMechanicalNonlinear") FreeCADGui.doCommand(command_to_run) # set the material nonlinear property of the solver to nonlinear if only one solver is available and if this solver is a CalculiX solver solver_object = None for m in FemGui.getActiveAnalysis().Member: if m.isDerivedFrom('Fem::FemSolverObjectPython'): if not solver_object: solver_object = m else: # we do not change the material nonlinear attribut if we have more than one solver solver_object = None break if solver_object and solver_object.SolverType == 'FemSolverCalculix': solver_object.MaterialNonlinearity = "nonlinear"
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create FemMeshGroup") FreeCADGui.addModule("ObjectsFem") self.mesh = FreeCADGui.Selection.getSelection()[0] # see 'with_gmsh_femmesh' in FemCommands for selection check FreeCADGui.doCommand("ObjectsFem.makeMeshGroup(FreeCAD.ActiveDocument, FreeCAD.ActiveDocument." + self.mesh.Name + ")") FreeCADGui.Selection.clearSelection()
def Activated(self): # check that the selection contains exactly what we want selection = FreeCADGui.Selection.getSelectionEx() if len(selection) != 1: FreeCAD.Console.PrintError(translate("PathFaceProfile","Please select one face or wire\n")) return if len(selection[0].SubObjects) != 1: FreeCAD.Console.PrintError(translate("PathFaceProfile","Please select only one face or wire\n")) return if not selection[0].SubObjects[0].ShapeType in ["Face","Wire"]: FreeCAD.Console.PrintError(translate("PathFaceProfile","Please select only a face or a wire\n")) return # if everything is ok, execute and register the transaction in the undo/redo stack FreeCAD.ActiveDocument.openTransaction("Create Profile") FreeCADGui.addModule("PathScripts.PathFaceProfile") FreeCADGui.addModule("PathScripts.PathUtils") FreeCADGui.doCommand('obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython","FaceProfile")') FreeCADGui.doCommand('PathScripts.PathFaceProfile.ObjectFaceProfile(obj)') FreeCADGui.doCommand('obj.Base = (FreeCAD.ActiveDocument.'+selection[0].ObjectName+',"'+selection[0].SubElementNames[0]+'")') FreeCADGui.doCommand('obj.ViewObject.Proxy = 0') FreeCADGui.doCommand('PathScripts.PathUtils.addToProject(obj)') FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute()
def has_nonpositive_jacobians(self): if '*ERROR in e_c3d: nonpositive jacobian' in self.ccx_stdout: nonpositive_jacobian_elements = [] nonpositive_jacobian_elenodes = [] for line in self.ccx_stdout.splitlines(): if 'determinant in element' in line: # print(line) # print(line.split()) non_posjac_ele = int(line.split()[3]) # print(non_posjac_ele) if non_posjac_ele not in nonpositive_jacobian_elements: nonpositive_jacobian_elements.append(non_posjac_ele) for e in nonpositive_jacobian_elements: for n in self.mesh.FemMesh.getElementNodes(e): nonpositive_jacobian_elenodes.append(n) nonpositive_jacobian_elements = sorted(nonpositive_jacobian_elements) nonpositive_jacobian_elenodes = sorted(nonpositive_jacobian_elenodes) command_for_nonposjacnodes = 'nonpositive_jacobian_elenodes = ' + str(nonpositive_jacobian_elenodes) command_to_highlight = "Gui.ActiveDocument." + self.mesh.Name + ".HighlightedNodes = nonpositive_jacobian_elenodes" # some output for the user FreeCAD.Console.PrintError('\n\nCalculiX returned an error due to nonpositive jacobian elements.\n') FreeCAD.Console.PrintMessage('nonpositive_jacobian_elements = {}\n'.format(nonpositive_jacobian_elements)) FreeCAD.Console.PrintMessage(command_for_nonposjacnodes + '\n') if FreeCAD.GuiUp: import FreeCADGui FreeCADGui.doCommand(command_for_nonposjacnodes) # with this the list nonpositive_jacobian_elenodes will be available for further user interaction FreeCAD.Console.PrintMessage('\n') FreeCADGui.doCommand(command_to_highlight) FreeCAD.Console.PrintMessage('\nFollowing some commands to copy which highlight the nonpositive jacobians or to reset the highlighted nodes:\n') FreeCAD.Console.PrintMessage(command_to_highlight + '\n') FreeCAD.Console.PrintMessage('Gui.ActiveDocument.' + self.mesh.Name + '.HighlightedNodes = []\n\n') # command to reset the Highlighted Nodes return True else: return False
def Activated(self): sel = FreeCADGui.Selection.getSelection() p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch") link = p.GetBool("FreeLinking",False) floorobj = [] warning = False for obj in sel : if not Draft.getType(obj) in ["Site", "Building"] : floorobj.append(obj) else : if link == True : floorobj.append(obj) else: warning = True if warning : message = translate( "Arch" , "You can put anything but Site, Building, Floor object in a Floor object.\n\ Floor object are not allowed to accept Site or Building object.\n\ Site, Building and Floor objects will be removed from the selection.\n\ You can change that in the preferences.\n" ) ArchCommands.printMessage( message ) if sel and len(floorobj) == 0: message = translate( "Arch" , "There is no valid object in the selection.\n\ Floor creation aborted.\n" ) ArchCommands.printMessage( message ) else : ss = "[ " for o in floorobj: ss += "FreeCAD.ActiveDocument." + o.Name + ", " ss += "]" FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Floor")) FreeCADGui.addModule("Arch") FreeCADGui.doCommand("Arch.makeFloor("+ss+")") FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute()
def Activated(self): global QtGui, QtCore from PyQt4 import QtGui, QtCore self.Width = 0.1 self.Height = 1 self.Align = "Center" self.continueCmd = False p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch") self.JOIN_WALLS = p.GetBool("joinWallSketches") sel = FreeCADGui.Selection.getSelection() done = False self.existing = [] if sel: import Draft if Draft.getType(sel[0]) != "Wall": FreeCAD.ActiveDocument.openTransaction(str(translate("Arch","Create Wall"))) FreeCADGui.doCommand('import Arch') for obj in sel: FreeCADGui.doCommand('Arch.makeWall(FreeCAD.ActiveDocument.'+obj.Name+')') FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() done = True if not done: import DraftTrackers self.points = [] self.tracker = DraftTrackers.boxTracker() FreeCADGui.Snapper.getPoint(callback=self.getPoint,extradlg=self.taskbox())
def has_no_material_assigned(self): if ' *ERROR in calinput: no material was assigned' in self.ccx_stdout: without_material_elements = [] without_material_elemnodes = [] for line in self.ccx_stdout.splitlines(): if 'to element' in line: # print(line) # print(line.split()) non_mat_ele = int(line.split()[2]) # print(non_mat_ele) if non_mat_ele not in without_material_elements: without_material_elements.append(non_mat_ele) for e in without_material_elements: for n in self.mesh.FemMesh.getElementNodes(e): without_material_elemnodes.append(n) without_material_elements = sorted(without_material_elements) without_material_elemnodes = sorted(without_material_elemnodes) command_for_withoutmatnodes = 'without_material_elemnodes = ' + str(without_material_elemnodes) command_to_highlight = "Gui.ActiveDocument." + self.mesh.Name + ".HighlightedNodes = without_material_elemnodes" # some output for the user FreeCAD.Console.PrintError('\n\nCalculiX returned an error due to elements without materials.\n') FreeCAD.Console.PrintMessage('without_material_elements = {}\n'.format(without_material_elements)) FreeCAD.Console.PrintMessage(command_for_withoutmatnodes + '\n') if FreeCAD.GuiUp: import FreeCADGui FreeCADGui.doCommand(command_for_withoutmatnodes) # with this the list without_material_elemnodes will be available for further user interaction FreeCAD.Console.PrintMessage('\n') FreeCADGui.doCommand(command_to_highlight) FreeCAD.Console.PrintMessage('\nFollowing some commands to copy which highlight the elements without materials or to reset the highlighted nodes:\n') FreeCAD.Console.PrintMessage(command_to_highlight + '\n') FreeCAD.Console.PrintMessage('Gui.ActiveDocument.' + self.mesh.Name + '.HighlightedNodes = []\n\n') # command to reset the Highlighted Nodes return True else: return False
def browse(self): url = self.prefs.GetString("BimServerUrl","http://localhost:8082")+"/apps/bimviews" if self.prefs.GetBool("BimServerBrowser",False): FreeCADGui.addModule("WebGui") FreeCADGui.doCommand("WebGui.openBrowser(\""+url+"\")") else: QtGui.QDesktopServices.openUrl(QtCore.QUrl(url, QtCore.QUrl.TolerantMode))
def curve_to_script(i,c): com = ["import FreeCAD", "from FreeCAD import Vector", "import Part",""] if isinstance(c,Part.BSplineCurve): com.append("poles%d = %r"%(i,c.getPoles())) com.append("weights%d = %r"%(i,c.getWeights())) com.append("knots%d = %r"%(i,c.getKnots())) com.append("mults%d = %r"%(i,c.getMultiplicities())) com.append("periodic%d = %r"%(i,c.isPeriodic())) com.append("degree%d = %s"%(i,c.Degree)) com.append("rational%d = %r"%(i,c.isRational())) com.append("bs%d = Part.BSplineCurve()"%i) #com.append("bs%d.buildFromPolesMultsKnots(poles%d, mults%d, knots%d, periodic%d, degree%d, )"%(i,i,i,i,i,i)) com.append("bs%d.buildFromPolesMultsKnots(poles%d, mults%d, knots%d, periodic%d, degree%d, weights%d, rational%d)"%(i,i,i,i,i,i,i,i)) com.append('obj%d = FreeCAD.ActiveDocument.addObject("Part::Spline","BSplineCurve%d")'%(i,i)) com.append('obj%d.Shape = bs%d.toShape()'%(i,i)) elif isinstance(c,Part.BezierCurve): com.append("poles%d = %r"%(i,c.getPoles())) #com.append("degree%d = %s"%(i,c.Degree)) com.append("be%d = Part.BezierCurve()"%i) com.append("be%d.increase(%s)"%(i,c.Degree)) com.append("be%d.setPoles(poles%d)"%(i,i)) if c.isRational(): w = c.getWeights() for j in range(len(w)): com.append("be%d.setWeight(%i,%f)"%(i,j+1,w[j])) com.append('obj%d = FreeCAD.ActiveDocument.addObject("Part::Spline","BezierCurve%d")'%(i,i)) com.append('obj%d.Shape = be%d.toShape()'%(i,i)) com.append("") for s in com: FreeCADGui.doCommand(s)
def Activated(self): # check that the selection contains exactly what we want selection = FreeCADGui.Selection.getSelection() if len(selection) != 1: FreeCAD.Console.PrintError( translate("Path_Array", "Please select exactly one path object\n")) return if not(selection[0].isDerivedFrom("Path::Feature")): FreeCAD.Console.PrintError( translate("Path_Array", "Please select exactly one path object\n")) return # if everything is ok, execute and register the transaction in the # undo/redo stack FreeCAD.ActiveDocument.openTransaction("Create Array") FreeCADGui.addModule("PathScripts.PathArray") FreeCADGui.addModule("PathScripts.PathUtils") FreeCADGui.doCommand( 'obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython","Array")') FreeCADGui.doCommand('PathScripts.PathArray.ObjectArray(obj)') FreeCADGui.doCommand( 'obj.Base = (FreeCAD.ActiveDocument.' + selection[0].Name + ')') # FreeCADGui.doCommand('PathScripts.PathArray.ViewProviderArray(obj.ViewObject)') FreeCADGui.doCommand('obj.ViewObject.Proxy = 0') FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)') FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute()
def has_for_nonpositive_jacobians(self): if '*ERROR in e_c3d: nonpositive jacobian' in self.ccx_stdout: print('CalculiX returned an error due to nonpositive jacobian elements.') nonpositive_jacobian_elements = [] nonpositive_jacobian_elenodes = [] for line in self.ccx_stdout.splitlines(): if 'determinant in element' in line: # print line # print line.split() non_posjac_ele = int(line.split()[3]) # print(non_posjac_ele) if non_posjac_ele not in nonpositive_jacobian_elements: nonpositive_jacobian_elements.append(non_posjac_ele) for e in nonpositive_jacobian_elements: for n in self.mesh.FemMesh.getElementNodes(e): nonpositive_jacobian_elenodes.append(n) nonpositive_jacobian_elements = sorted(nonpositive_jacobian_elements) nonpositive_jacobian_elenodes = sorted(nonpositive_jacobian_elenodes) command_for_nonposjacnodes = 'nonpositive_jacobian_elenodes = ' + str(nonpositive_jacobian_elenodes) command_to_highlight = "Gui.ActiveDocument." + self.mesh.Name + ".HighlightedNodes = nonpositive_jacobian_elenodes" print('nonpositive_jacobian_elements = ' + str(nonpositive_jacobian_elements)) print(command_for_nonposjacnodes) print(command_to_highlight) print('Gui.ActiveDocument.Extrude_Mesh.HighlightedNodes = []\n') # command to reset the Highlighted Nodes if FreeCAD.GuiUp: import FreeCADGui FreeCADGui.doCommand(command_for_nonposjacnodes) FreeCADGui.doCommand(command_to_highlight) return True else: return False
def Activated(self): FreeCAD.ActiveDocument.openTransaction(translate("Path_CompoundExtended","Create Compound")) FreeCADGui.addModule("PathScripts.PathCompoundExtended") snippet = ''' import Path import PathScripts from PathScripts import PathUtils incl = [] prjexists = False sel = FreeCADGui.Selection.getSelection() for s in sel: if s.isDerivedFrom("Path::Feature"): incl.append(s) obj = FreeCAD.ActiveDocument.addObject("Path::FeatureCompoundPython","Compound") PathScripts.PathCompoundExtended.ObjectCompoundExtended(obj) PathScripts.PathCompoundExtended.ViewProviderCompoundExtended(obj.ViewObject) project = PathUtils.addToProject(obj) if incl: children = [] p = project.Group g = obj.Group for child in incl: p.remove(child) children.append(FreeCAD.ActiveDocument.getObject(child.Name)) project.Group = p g.append(children) obj.Group = children ''' FreeCADGui.doCommand(snippet) FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute()
def Activated(self): # check that the selection contains exactly what we want selection = FreeCADGui.Selection.getSelection() if len(selection) != 1: FreeCAD.Console.PrintError( translate("Path_Hop", "Please select one path object\n")) return if not selection[0].isDerivedFrom("Path::Feature"): FreeCAD.Console.PrintError( translate("Path_Hop", "The selected object is not a path\n")) return FreeCAD.ActiveDocument.openTransaction( translate("Path_Hop", "Create Hop")) FreeCADGui.addModule("PathScripts.PathHop") FreeCADGui.addModule("PathScripts.PathUtils") FreeCADGui.doCommand( 'obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython","Hop")') FreeCADGui.doCommand('PathScripts.PathHop.ObjectHop(obj)') FreeCADGui.doCommand( 'PathScripts.PathHop.ViewProviderPathHop(obj.ViewObject)') FreeCADGui.doCommand( 'obj.NextObject = FreeCAD.ActiveDocument.' + selection[0].Name) FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)') FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute()
def Execute(cls, base, template): FreeCADGui.addModule('PathScripts.PathJobGui') if template: template = "'%s'" % template else: template = 'None' FreeCADGui.doCommand('PathScripts.PathJobGui.Create(App.ActiveDocument.%s, %s)' % (base.Name, template))
def open(filename): docname = os.path.splitext(os.path.basename(filename))[0] doc = FreeCAD.newDocument(docname) #All of the Gui.* calls in the Python console break after opening if we don't do this FreeCADGui.doCommand("import FreeCADGui as Gui") #Getting the main window will allow us to find the children we need to work with mw = FreeCADGui.getMainWindow() #We need this so we can load the file into it cqCodePane = mw.findChild(QtGui.QPlainTextEdit, "cqCodePane") #Pull the text of the CQ script file into our code pane cqCodePane.file.open(filename) execfile(filename) msg = QtGui.QApplication.translate( "cqCodeWidget", "Opened ", None, QtGui.QApplication.UnicodeUTF8) FreeCAD.Console.PrintMessage("\r\n" + msg + filename) return doc
def Activated(self): sel = FreeCADGui.Selection.getSelection() p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch") link = p.GetBool("FreeLinking",False) siteobj = [] warning = False for obj in sel : if Draft.getType(obj) == "Building": siteobj.append(obj) else : if link == True : siteobj.append(obj) else: warning = True if warning : message = translate( "Arch" , "Please select only Building objects or nothing!\n\ Site are not allowed to accept other object than Building.\n\ Other objects will be removed from the selection.\n\ You can change that in the preferences." ) ArchCommands.printMessage( message ) if sel and len(siteobj) == 0: message = translate( "Arch" , "There is no valid object in the selection.\n\ Site creation aborted." ) ArchCommands.printMessage( message ) else : ss = "[ " for o in siteobj: ss += "FreeCAD.ActiveDocument." + o.Name + ", " ss += "]" FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Site")) FreeCADGui.addModule("Arch") FreeCADGui.doCommand("Arch.makeSite("+ss+")") FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute()
def Activated(self): FreeCAD.ActiveDocument.openTransaction(translate( "PathStock", "Creates a 3D object to represent raw stock to mill the part out of")) FreeCADGui.addModule("PathScripts.PathStock") snippet = ''' import FreeCADGui if len(FreeCADGui.Selection.getSelection())>0: sel=FreeCADGui.Selection.getSelection() o = sel[0] if "Shape" in o.PropertiesList: obj =FreeCAD.ActiveDocument.addObject('Part::FeaturePython',sel[0].Name+('_Stock')) PathScripts.PathStock.Stock(obj) PathScripts.PathStock._ViewProviderStock(obj.ViewObject) PathScripts.PathUtils.addToJob(obj) baseobj = sel[0] obj.Base = baseobj FreeCADGui.ActiveDocument.getObject(sel[0].Name+("_Stock")).ShapeColor = (0.3333,0.6667,1.0000) FreeCADGui.ActiveDocument.getObject(sel[0].Name+("_Stock")).Transparency = 75 FreeCAD.ActiveDocument.recompute() else: FreeCAD.Console.PrintMessage("Select a Solid object and try again.\\n") else: FreeCAD.Console.PrintMessage("Select the object you want to show stock for and try again.\\n") ''' FreeCADGui.doCommand(snippet)
def Execute(cls, base, template): FreeCADGui.addModule('PathScripts.PathJobGui') if template: template = "'%s'" % template else: template = 'None' FreeCADGui.doCommand('PathScripts.PathJobGui.Create(%s, %s)' % ([o.Name for o in base], template))
def Activated(self): # if everything is ok, execute and register the transaction in the undo/redo stack FreeCAD.ActiveDocument.openTransaction(translate("Path_Drilling", "Create Drilling")) FreeCADGui.addModule("PathScripts.PathDrilling") FreeCADGui.doCommand('obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", "Drilling")') FreeCADGui.doCommand('PathScripts.PathDrilling.ObjectDrilling(obj)') FreeCADGui.doCommand('obj.Active = True') FreeCADGui.doCommand('PathScripts.PathDrilling._ViewProviderDrill(obj.ViewObject)') ztop = 10.0 zbottom = 0.0 FreeCADGui.doCommand('obj.ClearanceHeight = ' + str(ztop)) FreeCADGui.doCommand('obj.RetractHeight= ' + str(ztop)) FreeCADGui.doCommand('obj.FinalDepth=' + str(zbottom)) FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)') FreeCADGui.doCommand('obj.ToolController = PathScripts.PathUtils.findToolController(obj)') FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() FreeCADGui.doCommand('obj.ViewObject.startEditing()')
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create Mesh from FEMMesh") if self.selobj and not self.selobj2: # no result object selected FreeCADGui.addModule("femmesh.femmesh2mesh") FreeCADGui.doCommand( "out_mesh = femmesh.femmesh2mesh.femmesh_2_mesh(" "FreeCAD.ActiveDocument.{}.FemMesh)".format(self.selobj.Name)) FreeCADGui.addModule("Mesh") FreeCADGui.doCommand("Mesh.show(Mesh.Mesh(out_mesh))") FreeCADGui.doCommand("FreeCAD.ActiveDocument." + self.selobj.Name + ".ViewObject.hide()") if self.selobj and self.selobj2: femmesh = self.selobj res = self.selobj2 FreeCADGui.addModule("femmesh.femmesh2mesh") FreeCADGui.doCommand( "out_mesh = femmesh.femmesh2mesh.femmesh_2_mesh(" "FreeCAD.ActiveDocument.{}.FemMesh, FreeCAD.ActiveDocument.{})" .format(femmesh.Name, res.Name)) FreeCADGui.addModule("Mesh") FreeCADGui.doCommand("Mesh.show(Mesh.Mesh(out_mesh))") FreeCADGui.doCommand("FreeCAD.ActiveDocument." + femmesh.Name + ".ViewObject.hide()") FreeCADGui.Selection.clearSelection() FreeCAD.ActiveDocument.recompute()
def Activated(self): FreeCADGui.addModule("MaterialEditor") FreeCADGui.doCommand("MaterialEditor.openEditor()")
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create FemElementGeometry2D") FreeCADGui.addModule("ObjectsFem") FreeCADGui.doCommand( "FemGui.getActiveAnalysis().addObject(ObjectsFem.makeElementGeometry2D(FreeCAD.ActiveDocument))" )
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create SolverZ88") FreeCADGui.addModule("ObjectsFem") FreeCADGui.doCommand( "FemGui.getActiveAnalysis().addObject(ObjectsFem.makeSolverZ88(FreeCAD.ActiveDocument))" )
def addSelection(self, doc, obj, sub, pnt): FreeCADGui.doCommand( 'Gui.Selection.addSelection(FreeCAD.ActiveDocument.' + obj + ')') FreeCADGui.updateGui()
def Activated(self): ztop = 10.0 zbottom = 0.0 FreeCAD.ActiveDocument.openTransaction( translate("Path", "Create a Profile based on edge selection")) FreeCADGui.addModule("PathScripts.PathProfile") FreeCADGui.doCommand( 'obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", "Edge Profile")' ) FreeCADGui.doCommand('PathScripts.PathProfileEdges.ObjectProfile(obj)') FreeCADGui.doCommand( 'PathScripts.PathProfileEdges._ViewProviderProfile(obj.ViewObject)' ) FreeCADGui.doCommand('obj.Active = True') FreeCADGui.doCommand('obj.ClearanceHeight = ' + str(ztop + 10.0)) FreeCADGui.doCommand('obj.StepDown = 1.0') FreeCADGui.doCommand('obj.StartDepth= ' + str(ztop)) FreeCADGui.doCommand('obj.FinalDepth=' + str(zbottom)) FreeCADGui.doCommand('obj.SafeHeight = ' + str(ztop + 2.0)) FreeCADGui.doCommand('obj.Side = "On"') FreeCADGui.doCommand('obj.OffsetExtra = 0.0') FreeCADGui.doCommand('obj.Direction = "CW"') FreeCADGui.doCommand('obj.UseComp = True') FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)') FreeCADGui.doCommand( 'obj.ToolController = PathScripts.PathUtils.findToolController(obj)' ) FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() FreeCADGui.doCommand('obj.ViewObject.startEditing()')
def Activated(self): sel = FreeCADGui.Selection.getSelectionEx() if sel: obj = sel[0].Object if Draft.getType(obj) == "Structure": if len(sel) > 1: sk = sel[1].Object if sk.isDerivedFrom("Part::Feature"): if len(sk.Shape.Wires) == 1: # we have a base object and a sketch: create the rebar now FreeCAD.ActiveDocument.openTransaction( translate("Arch", "Create Rebar")) FreeCADGui.addModule("Arch") FreeCADGui.doCommand( "Arch.makeRebar(FreeCAD.ActiveDocument." + obj.Name + ",FreeCAD.ActiveDocument." + sk.Name + ")") FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() return else: # we have only a base object: open the sketcher FreeCADGui.activateWorkbench("SketcherWorkbench") FreeCADGui.runCommand("Sketcher_NewSketch") FreeCAD.ArchObserver = ArchComponent.ArchSelectionObserver( obj, FreeCAD.ActiveDocument.Objects[-1], hide=False, nextCommand="Arch_Rebar") FreeCADGui.Selection.addObserver(FreeCAD.ArchObserver) return elif obj.isDerivedFrom("Part::Feature"): if len(obj.Shape.Wires) == 1: # we have only the sketch: extract the base object from it if hasattr(obj, "Support"): if obj.Support: if len(obj.Support) != 0: sup = obj.Support[0][0] else: print( "Arch: error: couldn't extract a base object" ) return FreeCAD.ActiveDocument.openTransaction( translate("Arch", "Create Rebar")) FreeCADGui.addModule("Arch") FreeCADGui.doCommand( "Arch.makeRebar(FreeCAD.ActiveDocument." + sup.Name + ",FreeCAD.ActiveDocument." + obj.Name + ")") FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() return else: print( "Arch: error: couldn't extract a base object") return FreeCAD.Console.PrintMessage( translate("Arch", "Please select a base face on a structural object") + "\n") FreeCADGui.Control.closeDialog() FreeCADGui.Control.showDialog(ArchComponent.SelectionTaskPanel()) FreeCAD.ArchObserver = ArchComponent.ArchSelectionObserver( nextCommand="Arch_Rebar") FreeCADGui.Selection.addObserver(FreeCAD.ArchObserver)
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create FemShellThickness") FreeCADGui.addModule("FemShellThickness") FreeCADGui.doCommand("FemGui.getActiveAnalysis().Member = FemGui.getActiveAnalysis().Member + [FemShellThickness.makeFemShellThickness()]")
def Activated(self): ztop = 10.0 zbottom = 0.0 FreeCAD.ActiveDocument.openTransaction( translate("Path", "Create a Profile")) FreeCADGui.addModule("PathScripts.PathProfile") FreeCADGui.doCommand( 'obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", "Profile")' ) FreeCADGui.doCommand('PathScripts.PathProfile.ObjectProfile(obj)') FreeCADGui.doCommand('obj.Active = True') FreeCADGui.doCommand('obj.ClearanceHeight = ' + str(ztop + 10.0)) FreeCADGui.doCommand('obj.StepDown = 1.0') FreeCADGui.doCommand('obj.StartDepth= ' + str(ztop)) FreeCADGui.doCommand('obj.FinalDepth=' + str(zbottom)) FreeCADGui.doCommand('obj.SafeHeight = ' + str(ztop + 2.0)) FreeCADGui.doCommand('obj.Side = "Left"') FreeCADGui.doCommand('obj.OffsetExtra = 0.0') FreeCADGui.doCommand('obj.Direction = "CCW"') FreeCADGui.doCommand('obj.UseComp = False') FreeCADGui.doCommand('obj.processHoles = False') FreeCADGui.doCommand('obj.processPerimeter = True') FreeCADGui.doCommand('obj.PlungeAngle = 90.0') FreeCADGui.doCommand( 'PathScripts.PathProfile._ViewProviderProfile(obj.ViewObject)') FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)') FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() FreeCADGui.doCommand('obj.ViewObject.startEditing()')
def Activated(self): s = FreeCADGui.Selection.getSelection() if len(s) != 1: FreeCAD.Console.PrintError( translate("Arch", "You must select exactly one base object")) else: obj = s[0] if not obj.isDerivedFrom("Mesh::Feature"): FreeCAD.Console.PrintError( translate("Arch", "The selected object must be a mesh")) else: if obj.Mesh.CountFacets > 1000: msgBox = QtGui.QMessageBox() msgBox.setText( translate("Arch", "This mesh has more than 1000 facets.")) msgBox.setInformativeText( translate( "Arch", "This operation can take a long time. Proceed?")) msgBox.setStandardButtons(QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel) msgBox.setDefaultButton(QtGui.QMessageBox.Cancel) ret = msgBox.exec_() if ret == QtGui.QMessageBox.Cancel: return elif obj.Mesh.CountFacets >= 500: FreeCAD.Console.PrintWarning( translate( "Arch", "The mesh has more than 500 facets. This will take a couple of minutes..." )) FreeCAD.ActiveDocument.openTransaction( str(translate("Arch", "Create 3 views"))) FreeCADGui.addModule("Arch") FreeCADGui.addModule("Part") FreeCADGui.doCommand( "s1 = Arch.createMeshView(FreeCAD.ActiveDocument." + obj.Name + ",FreeCAD.Vector(0,0,-1),outeronly=False,largestonly=False)" ) FreeCADGui.doCommand("Part.show(s1)") FreeCADGui.doCommand( "s2 = Arch.createMeshView(FreeCAD.ActiveDocument." + obj.Name + ",FreeCAD.Vector(1,0,0),outeronly=False,largestonly=False)" ) FreeCADGui.doCommand("Part.show(s2)") FreeCADGui.doCommand( "s3 = Arch.createMeshView(FreeCAD.ActiveDocument." + obj.Name + ",FreeCAD.Vector(0,1,0),outeronly=False,largestonly=False)" ) FreeCADGui.doCommand("Part.show(s3)") FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() return
def Activated(self): # check that the selection contains exactly what we want selection = FreeCADGui.Selection.getSelection() if len(selection) != 1: FreeCAD.Console.PrintError( translate("Path_SimpleCopy", "Please select exactly one path object")+"\n") return if not(selection[0].isDerivedFrom("Path::Feature")): FreeCAD.Console.PrintError( translate("Path_SimpleCopy", "Please select exactly one path object")+"\n") return FreeCAD.ActiveDocument.openTransaction( translate("Path_SimpleCopy", "Simple Copy")) FreeCADGui.doCommand("srcpath = FreeCADGui.Selection.getSelectionEx()[0].Object.Path\n") FreeCADGui.addModule("PathScripts.PathUtils") FreeCADGui.addModule("PathScripts.PathCustom") FreeCADGui.doCommand('obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython","' + selection[0].Name + '_SimpleCopy")') FreeCADGui.doCommand('PathScripts.PathCustom.ObjectCustom(obj)') FreeCADGui.doCommand('obj.ViewObject.Proxy = 0') FreeCADGui.doCommand('obj.Gcode = [c.toGCode() for c in srcpath.Commands]') FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)') FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute()
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create Elmer solver object") FreeCADGui.addModule("ObjectsFem") FreeCADGui.doCommand("FemGui.getActiveAnalysis().addObject(ObjectsFem.makeSolverElmer(FreeCAD.ActiveDocument))") FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute()
def getPoint(self, point=None, obj=None): "this function is called by the snapper when it has a 3D point" if obj: if Draft.getType(obj) == "Wall": if not obj in self.existing: self.existing.append(obj) if point == None: self.tracker.finalize() return self.points.append(point) if len(self.points) == 1: self.tracker.on() FreeCADGui.Snapper.getPoint(last=self.points[0], callback=self.getPoint, movecallback=self.update, extradlg=self.taskbox()) elif len(self.points) == 2: import Part l = Part.Line(self.points[0], self.points[1]) self.tracker.finalize() FreeCAD.ActiveDocument.openTransaction( translate("Arch", "Create Wall")) FreeCADGui.doCommand('import Arch') FreeCADGui.doCommand('import Part') FreeCADGui.doCommand('trace=Part.Line(FreeCAD.' + str(l.StartPoint) + ',FreeCAD.' + str(l.EndPoint) + ')') if not self.existing: # no existing wall snapped, just add a default wall self.addDefault(l) else: if self.JOIN_WALLS_SKETCHES: # join existing subwalls first if possible, then add the new one w = joinWalls(self.existing) if w: if areSameWallTypes([w, self]): FreeCADGui.doCommand('FreeCAD.ActiveDocument.' + w.Name + '.Base.addGeometry(trace)') else: # if not possible, add new wall as addition to the existing one self.addDefault(l) if self.AUTOJOIN: FreeCADGui.doCommand( 'Arch.addComponents(FreeCAD.ActiveDocument.' + FreeCAD.ActiveDocument.Objects[-1].Name + ',FreeCAD.ActiveDocument.' + w.Name + ')') else: self.addDefault(l) else: # add new wall as addition to the first existing one self.addDefault(l) if self.AUTOJOIN: FreeCADGui.doCommand( 'Arch.addComponents(FreeCAD.ActiveDocument.' + FreeCAD.ActiveDocument.Objects[-1].Name + ',FreeCAD.ActiveDocument.' + self.existing[0].Name + ')') FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() if self.continueCmd: self.Activated()
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create Solid Material") FreeCADGui.addModule("ObjectsFem") FreeCADGui.doCommand("FemGui.getActiveAnalysis().addObject(ObjectsFem.makeMaterialSolid(FreeCAD.ActiveDocument, 'SolidMaterial'))") FreeCADGui.doCommand("FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)") FreeCAD.ActiveDocument.recompute()
def getPoint(self, point=None, obj=None): "this function is called by the snapper when it has a 3D point" self.tracker.finalize() if point == None: return FreeCAD.ActiveDocument.openTransaction( str(translate("Arch", "Create Structure"))) FreeCADGui.doCommand('import Arch') if self.Profile: pr = Presets[self.Profile] FreeCADGui.doCommand('p = Arch.makeProfile(' + str(pr[2]) + ',' + str(pr[3]) + ',' + str(pr[4]) + ',' + str(pr[5]) + ')') if self.Length == pr[2]: # vertical FreeCADGui.doCommand('s = Arch.makeStructure(p,height=' + str(self.Height) + ')') else: # horizontal FreeCADGui.doCommand('s = Arch.makeStructure(p,height=' + str(self.Length) + ')') FreeCADGui.doCommand( 's.Placement.Rotation = FreeCAD.Rotation(-0.5,0.5,-0.5,0.5)' ) else: FreeCADGui.doCommand('s = Arch.makeStructure(length=' + str(self.Length) + ',width=' + str(self.Width) + ',height=' + str(self.Height) + ')') FreeCADGui.doCommand('s.Placement.Base = ' + DraftVecUtils.toString(point)) FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() if self.continueCmd: self.Activated()
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create FemConstraintSelfWeight") FreeCADGui.addModule("ObjectsFem") FreeCADGui.doCommand("FemGui.getActiveAnalysis().addObject(ObjectsFem.makeConstraintSelfWeight(FreeCAD.ActiveDocument))") FreeCAD.ActiveDocument.recompute()
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Clear FEM mesh") FreeCADGui.addModule("Fem") FreeCADGui.doCommand("FreeCAD.ActiveDocument." + self.selobj.Name + ".FemMesh = Fem.FemMesh()") FreeCADGui.Selection.clearSelection() FreeCAD.ActiveDocument.recompute()
def Activated(self): doc = '' obj = '' sublinks = '(' doc_num = 0 obj_num = 0 face_num = 0 edge_num = 0 vert_num = 0 selection = FreeCADGui.Selection.getSelectionEx() if selection == []: FreeCAD.Console.PrintError('Selection is empty.\n') for selobj in selection: if not selobj.DocumentName == doc: doc = selobj.DocumentName doc_num += 1 FreeCADGui.doCommand( "doc{} = FreeCAD.getDocument('{}')".format(doc_num, doc)) if not selobj.ObjectName == obj: obj = selobj.ObjectName obj_num += 1 FreeCADGui.doCommand("o{} = doc{}.getObject('{}')".format( obj_num, doc_num, obj)) if selobj.HasSubObjects: for sub in selobj.SubElementNames: sublinks += "(o{},('{}')),".format(obj_num, sub) if 'Vertex' in sub: vert_num += 1 FreeCADGui.doCommand("v{} = o{}.Shape.{}".format( vert_num, obj_num, sub)) if 'Edge' in sub: edge_num += 1 FreeCADGui.doCommand("e{} = o{}.Shape.{}".format( edge_num, obj_num, sub)) if 'Face' in sub: face_num += 1 FreeCADGui.doCommand("f{} = o{}.Shape.{}".format( face_num, obj_num, sub)) sublinks += ")" if len(sublinks) > 1: FreeCADGui.doCommand("_sub_link_buffer = {}".format(sublinks)) if obj_num > 1: ol = '' for oi in range(obj_num): ol += "o{},".format(oi + 1) FreeCADGui.doCommand("ol = ({})".format(ol)) if vert_num > 1: vl = '' for vi in range(vert_num): vl += "v{},".format(vi + 1) FreeCADGui.doCommand("vl = ({})".format(vl)) if edge_num > 1: el = '' for ei in range(edge_num): el += "e{},".format(ei + 1) FreeCADGui.doCommand("el = ({})".format(el)) if face_num > 1: fl = '' for fi in range(face_num): fl += "f{},".format(fi + 1) FreeCADGui.doCommand("fl = ({})".format(fl))
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create FemEquationHeat") FreeCADGui.addModule("ObjectsFem") FreeCADGui.doCommand("ObjectsFem.makeEquationHeat(FreeCAD.ActiveDocument, FreeCAD.ActiveDocument." + self.selobj.Name + ")") FreeCADGui.Selection.clearSelection() FreeCAD.ActiveDocument.recompute()
def createGroup(self): if hasattr(self, "Object"): s = "FreeCAD.ActiveDocument.getObject(\"%s\").newObject(\"App::DocumentObjectGroup\",\"Group\")" % self.Object.Name FreeCADGui.doCommand(s)
def accept(self): self.obj.InitialVariables = self.InitialVariables doc = FreeCADGui.getDocument(self.obj.Document) doc.resetEdit() FreeCADGui.doCommand( "\n# Values are converted to SI units and stored (eg. m/s)") FreeCADGui.doCommand( "init = FreeCAD.ActiveDocument.{}.InitialVariables".format( self.obj.Name)) FreeCADGui.doCommand("init['PotentialFoam'] = {}".format( self.InitialVariables['PotentialFoam'])) FreeCADGui.doCommand("init['Ux'] = {}".format( self.InitialVariables['Ux'])) FreeCADGui.doCommand("init['Uy'] = {}".format( self.InitialVariables['Uy'])) FreeCADGui.doCommand("init['Uz'] = {}".format( self.InitialVariables['Uz'])) FreeCADGui.doCommand("init['Pressure'] = {}".format( self.InitialVariables['Pressure'])) FreeCADGui.doCommand( "init['UseInletTurbulenceValues'] " "= {}".format(self.InitialVariables['UseInletTurbulenceValues'])) FreeCADGui.doCommand("init['omega'] = {}".format( self.InitialVariables['omega'])) FreeCADGui.doCommand("init['k'] = {}".format( self.InitialVariables['k'])) FreeCADGui.doCommand( "FreeCAD.ActiveDocument.{}.InitialVariables = init".format( self.obj.Name))
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create OpenFOAM Solver") FreeCADGui.addModule("CfdSolverFoam") FreeCADGui.doCommand( "FemGui.getActiveAnalysis().Member = FemGui.getActiveAnalysis().Member + [CfdSolverFoam.makeCfdSolverFoam()]" )
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create CFD Analysis") FreeCADGui.addModule("FemGui") FreeCADGui.addModule("CfdAnalysis") FreeCADGui.doCommand("CfdAnalysis.makeCfdAnalysis('CfdAnalysis')") FreeCADGui.doCommand("FemGui.setActiveAnalysis(App.activeDocument().ActiveObject)") FreeCADGui.addModule("CfdSolverFoam") FreeCADGui.doCommand("FemGui.getActiveAnalysis().Member = FemGui.getActiveAnalysis().Member + [CfdSolverFoam.makeCfdSolverFoam()]") FreeCADGui.addModule("CfdFluidMaterial") FreeCADGui.doCommand("FemGui.getActiveAnalysis().Member = FemGui.getActiveAnalysis().Member + [CfdFluidMaterial.makeCfdFluidMaterial('FluidMaterial')]") sel = FreeCADGui.Selection.getSelection() if (len(sel) == 1): if(sel[0].isDerivedFrom("Fem::FemMeshObject")): FreeCADGui.doCommand("FemGui.getActiveAnalysis().Member = FemGui.getActiveAnalysis().Member + [App.activeDocument()." + sel[0].Name + "]") if(sel[0].isDerivedFrom("Part::Feature")): FreeCADGui.doCommand("App.activeDocument().addObject('Fem::FemMeshShapeGmshObject', '" + sel[0].Name + "_Mesh')") # default to GMSH FreeCADGui.doCommand("App.activeDocument().ActiveObject.Shape = App.activeDocument()." + sel[0].Name) FreeCADGui.doCommand("FemGui.getActiveAnalysis().Member = FemGui.getActiveAnalysis().Member + [App.activeDocument().ActiveObject]") FreeCADGui.doCommand("Gui.activeDocument().setEdit(App.ActiveDocument.ActiveObject.Name)") FreeCADGui.Selection.clearSelection()
def Activated(self): FreeCADGui.addModule("femexamples.examplesgui") FreeCADGui.doCommand("femexamples.examplesgui.show_examplegui()")
def accept(self): if self.obj.Label.startswith("CfdFluidBoundary"): self.obj.Label = self.obj.BoundaryType FreeCADGui.Selection.removeObserver(self) doc = FreeCADGui.getDocument(self.obj.Document) doc.resetEdit() FreeCADGui.doCommand("\nbc = FreeCAD.ActiveDocument.{}".format( self.obj.Name)) # Type FreeCADGui.doCommand("bc.BoundaryType " "= '{}'".format(self.obj.BoundaryType)) FreeCADGui.doCommand("bc.BoundarySubType " "= '{}'".format(self.obj.BoundarySubType)) FreeCADGui.doCommand( "bc.ThermalBoundaryType " "= '{}'".format(CfdFluidBoundary.THERMAL_BOUNDARY_TYPES[ self.form.comboThermalBoundaryType.currentIndex()])) # Velocity FreeCADGui.doCommand("bc.VelocityIsCartesian " "= {}".format( self.form.radioButtonCart.isChecked())) FreeCADGui.doCommand("bc.Ux " "= '{}'".format(getQuantity( self.form.inputCartX))) FreeCADGui.doCommand("bc.Uy " "= '{}'".format(getQuantity( self.form.inputCartY))) FreeCADGui.doCommand("bc.Uz " "= '{}'".format(getQuantity( self.form.inputCartZ))) FreeCADGui.doCommand("bc.VelocityMag " "= '{}'".format( getQuantity(self.form.inputVelocityMag))) FreeCADGui.doCommand("bc.DirectionFace " "= '{}'".format(self.form.lineDirection.text())) FreeCADGui.doCommand("bc.ReverseNormal " "= {}".format(self.form.checkReverse.isChecked())) FreeCADGui.doCommand("bc.MassFlowRate " "= '{}'".format( getQuantity(self.form.inputMassFlowRate))) FreeCADGui.doCommand("bc.VolFlowRate " "= '{}'".format( getQuantity(self.form.inputVolFlowRate))) # Presure FreeCADGui.doCommand("bc.Pressure " "= '{}'".format( getQuantity(self.form.inputPressure))) # Wall FreeCADGui.doCommand("bc.SlipRatio " "= '{}'".format( getQuantity(self.form.inputSlipRatio))) # Thermal FreeCADGui.doCommand("bc.Temperature " "= '{}'".format( getQuantity(self.form.inputTemperature))) FreeCADGui.doCommand("bc.HeatFlux " "= '{}'".format( getQuantity(self.form.inputHeatFlux))) FreeCADGui.doCommand( "bc.HeatTransferCoeff " "= '{}'".format(getQuantity(self.form.inputHeatTransferCoeff))) # Turbulence if self.turbModel in CfdFluidBoundary.TURBULENT_INLET_SPEC: turb_index = self.form.comboTurbulenceSpecification.currentIndex() FreeCADGui.doCommand("bc.TurbulenceInletSpecification " "= '{}'".format( CfdFluidBoundary.TURBULENT_INLET_SPEC[ self.turbModel][1][turb_index])) else: FreeCADGui.doCommand("bc.TurbulenceInletSpecification " "= '{}'".format( self.obj.TurbulenceInletSpecification)) FreeCADGui.doCommand("bc.TurbulentKineticEnergy " "= '{}'".format( getQuantity(self.form.inputKineticEnergy))) FreeCADGui.doCommand("bc.SpecificDissipationRate " "= '{}'".format( getQuantity( self.form.inputSpecificDissipationRate))) FreeCADGui.doCommand("bc.TurbulenceIntensity " "= '{}'".format( getQuantity(self.form.inputIntensity))) FreeCADGui.doCommand("bc.TurbulenceLengthScale " "= '{}'".format( getQuantity(self.form.inputLengthScale))) FreeCADGui.doCommand("bc.VolumeFractions = {}".format(self.alphas)) # Porous FreeCADGui.doCommand("bc.PorousBaffleMethod " "= '{}'".format(CfdFluidBoundary.POROUS_METHODS[ self.form.buttonGroupPorous.checkedId()])) FreeCADGui.doCommand( "bc.PressureDropCoeff " "= '{}'".format(getQuantity(self.form.inputPressureDropCoeff))) FreeCADGui.doCommand("bc.ScreenWireDiameter " "= '{}'".format( getQuantity(self.form.inputWireDiameter))) FreeCADGui.doCommand("bc.ScreenSpacing " "= '{}'".format( getQuantity(self.form.inputSpacing))) FreeCADGui.doCommand("FreeCAD.ActiveDocument.{}.Label = '{}'".format( self.obj.Name, self.obj.Label)) refstr = "FreeCAD.ActiveDocument.{}.References = [\n".format( self.obj.Name) refstr += ',\n'.join("{}".format(ref) for ref in self.obj.References) refstr += "]" FreeCADGui.doCommand(refstr) FreeCADGui.doCommand("FreeCAD.ActiveDocument.recompute()") self.faceSelector.closing()
def addDefault(self,l): FreeCADGui.addModule("Draft") if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetBool("WallSketches",True): FreeCADGui.doCommand('base=FreeCAD.ActiveDocument.addObject("Sketcher::SketchObject","WallTrace")') FreeCADGui.doCommand('base.Placement = FreeCAD.DraftWorkingPlane.getPlacement()') FreeCADGui.doCommand('base.addGeometry(trace)') else: FreeCADGui.doCommand('base=Draft.makeLine(trace)') FreeCADGui.doCommand('FreeCAD.ActiveDocument.recompute()') FreeCADGui.doCommand('wall = Arch.makeWall(base,width='+str(self.Width)+',height='+str(self.Height)+',align="'+str(self.Align)+'")') FreeCADGui.doCommand('wall.Normal = FreeCAD.DraftWorkingPlane.getNormal()') if self.MultiMat: FreeCADGui.doCommand("wall.Material = FreeCAD.ActiveDocument."+self.MultiMat.Name) FreeCADGui.doCommand("Draft.autogroup(wall)")
def Activated(self): FreeCADGui.doCommand("import CurvedShapes") FreeCADGui.doCommand("import NotchConnector") selection = FreeCADGui.Selection.getSelection() if len(selection) < 2: return for sel in selection: if sel == selection[0]: FreeCADGui.doCommand( "base = FreeCAD.ActiveDocument.getObject('%s')" % (sel.Name)) elif sel == selection[1]: FreeCADGui.doCommand( "tools = [FreeCAD.ActiveDocument.getObject('%s')]" % (sel.Name)) else: FreeCADGui.doCommand( "tools.append(FreeCAD.ActiveDocument.getObject('%s'))" % (sel.Name)) FreeCADGui.doCommand( "CurvedShapes.makeNotchConnector(base, tools, CutDepth=50.0)") if len(selection) == 2: FreeCADGui.doCommand( "CurvedShapes.makeNotchConnector(tools[0], [base], CutDepth=-50.0)" ) FreeCAD.ActiveDocument.recompute()
def accept(self): doc = FreeCADGui.getDocument(self.obj.Document) doc.resetEdit() # Macro script FreeCADGui.doCommand("\nobj = FreeCAD.ActiveDocument.{}".format( self.obj.Name)) FreeCADGui.doCommand("obj.RefinementInterval = {}".format( int(self.form.sb_refinement_interval.value()))) FreeCADGui.doCommand("obj.MaxRefinementLevel = {}".format( int(self.form.sb_max_refinement_levels.value()))) FreeCADGui.doCommand("obj.BufferLayers = {}".format( int(self.form.sb_no_buffer_layers.value()))) FreeCADGui.doCommand("obj.MaxRefinementCells = {}".format( int(ceil(float(getQuantity(self.form.if_max_cells)))))) FreeCADGui.doCommand("obj.RefinementField = '{}'".format( self.form.le_refinement_field.text())) FreeCADGui.doCommand("obj.LowerRefinementLevel = {}".format( getQuantity(self.form.if_lower_refinement))) FreeCADGui.doCommand("obj.UpperRefinementLevel = {}".format( getQuantity(self.form.if_upper_refinement))) FreeCADGui.doCommand("obj.UnRefinementLevel = {}".format( int(float(getQuantity(self.form.if_unrefine_level))))) FreeCADGui.doCommand("obj.WriteFields = {}".format( self.form.cb_write_refinement_volscalarfield.isChecked())) # Finalise FreeCADGui.doCommand("FreeCAD.ActiveDocument.recompute()")
def set_mesh_params(self): FreeCADGui.doCommand( "\nFreeCAD.ActiveDocument.{}.CharacteristicLengthMax " "= '{}'".format(self.mesh_obj.Name, self.clmax)) FreeCADGui.doCommand("FreeCAD.ActiveDocument.{}.MeshUtility " "= '{}'".format(self.mesh_obj.Name, self.utility)) FreeCADGui.doCommand("FreeCAD.ActiveDocument.{}.ElementDimension " "= '{}'".format(self.mesh_obj.Name, self.dimension)) FreeCADGui.doCommand("FreeCAD.ActiveDocument.{}.CellsBetweenLevels " "= {}".format(self.mesh_obj.Name, self.cellsbetweenlevels)) FreeCADGui.doCommand("FreeCAD.ActiveDocument.{}.EdgeRefinement " "= {}".format(self.mesh_obj.Name, self.edgerefine)) FreeCADGui.doCommand("FreeCAD.ActiveDocument.{}.PointInMesh " "= {}".format(self.mesh_obj.Name, self.PointInMesh))