def Activated(self): MatObj = None for i in FemGui.getActiveAnalysis().Member: if i.isDerivedFrom("App::MaterialObject"): MatObj = i if not MatObj: femDoc = FemGui.getActiveAnalysis().Document if FreeCAD.ActiveDocument is not femDoc: FreeCADGui.setActiveDocument(femDoc) FreeCAD.ActiveDocument.openTransaction("Create Material") FreeCADGui.addModule("MechanicalMaterial") FreeCADGui.doCommand("MechanicalMaterial.makeMechanicalMaterial('MechanicalMaterial')") FreeCADGui.doCommand( "App.activeDocument()." + FemGui.getActiveAnalysis().Name + ".Member = App.activeDocument()." + FemGui.getActiveAnalysis().Name + ".Member + [App.ActiveDocument.ActiveObject]" ) FreeCADGui.doCommand("Gui.activeDocument().setEdit(App.ActiveDocument.ActiveObject.Name,0)") # FreeCADGui.doCommand("Fem.makeMaterial()") else: if FreeCAD.ActiveDocument is not MatObj.Document: FreeCADGui.setActiveDocument(MatObj.Document) FreeCADGui.doCommand("Gui.activeDocument().setEdit('" + MatObj.Name + "',0)")
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 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.addModule("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)') FreeCADGui.doCommand('s.Profile = "'+pr[1]+'"') 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)) FreeCADGui.doCommand('s.Placement.Rotation=FreeCAD.DraftWorkingPlane.getRotation().Rotation') FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() if self.continueCmd: self.Activated()
def Activated(self): ztop = 10 zbottom = 0 FreeCAD.ActiveDocument.openTransaction( translate("Path_Surfacing", "Create Surface")) FreeCADGui.addModule("PathScripts.PathSurface") FreeCADGui.doCommand( 'obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython","Surface")') FreeCADGui.doCommand('PathScripts.PathSurface.ObjectSurface(obj)') FreeCADGui.doCommand('obj.Active = True') FreeCADGui.doCommand( 'PathScripts.PathSurface.ViewProviderSurface(obj.ViewObject)') FreeCADGui.doCommand('from PathScripts import PathUtils') FreeCADGui.doCommand('obj.ClearanceHeight = ' + str(ztop + 2)) FreeCADGui.doCommand('obj.StartDepth = ' + str(ztop)) FreeCADGui.doCommand('obj.SafeHeight = ' + str(ztop + 2)) FreeCADGui.doCommand('obj.StepDown = ' + str((ztop - zbottom) / 8)) FreeCADGui.doCommand('obj.SampleInterval = 0.4') FreeCADGui.doCommand('obj.FinalDepth=' + str(zbottom)) FreeCADGui.doCommand('PathScripts.PathUtils.addToProject(obj)') FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() FreeCADGui.doCommand('obj.ViewObject.startEditing()')
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 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_DressupAxisMap", "Create Dress-up")) FreeCADGui.addModule("PathScripts.PathDressupAxisMap") FreeCADGui.addModule("PathScripts.PathUtils") FreeCADGui.doCommand('obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", "AxisMapDressup")') FreeCADGui.doCommand('PathScripts.PathDressupAxisMap.ObjectDressup(obj)') FreeCADGui.doCommand('obj.Base = FreeCAD.ActiveDocument.' + selection[0].Name) FreeCADGui.doCommand('obj.Radius = 45') FreeCADGui.doCommand('PathScripts.PathDressupAxisMap.ViewProviderDressup(obj.ViewObject)') FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)') FreeCADGui.doCommand('Gui.ActiveDocument.getObject(obj.Base.Name).Visibility = False') FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute()
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Print FEM mesh info") FreeCADGui.doCommand("print(App.ActiveDocument." + self.selobj.Name + ".FemMesh)") FreeCADGui.addModule("PySide") FreeCADGui.doCommand("mesh_info = str(App.ActiveDocument." + self.selobj.Name + ".FemMesh)") FreeCADGui.doCommand("PySide.QtGui.QMessageBox.information(None, 'FEM Mesh Info', mesh_info)") FreeCADGui.Selection.clearSelection()
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('PathScripts.PathProfile._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 = "Left"') FreeCADGui.doCommand('obj.OffsetExtra = 0.0') FreeCADGui.doCommand('obj.Direction = "CW"') FreeCADGui.doCommand('obj.UseComp = False') FreeCADGui.doCommand('obj.PlungeAngle = 90.0') FreeCADGui.doCommand('PathScripts.PathUtils.addToProject(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): 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 CreateModule(name): App.ActiveDocument.openTransaction("Create Module") Gui.addModule("PartOMagic.Features.Module") Gui.doCommand("f = PartOMagic.Features.Module.makeModule(name = '"+name+"')") Gui.doCommand("PartOMagic.Base.Containers.setActiveContainer(f)") Gui.doCommand("Gui.Selection.clearSelection()") App.ActiveDocument.commitTransaction()
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): 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): # check that the selection contains exactly what we want selection = FreeCADGui.Selection.getSelection() if len(selection) != 1: PathLog.error(translate("Please select one path object") + "\n") return baseObject = selection[0] if not baseObject.isDerivedFrom("Path::Feature"): PathLog.error(translate("The selected object is not a path") + "\n") return if baseObject.isDerivedFrom("Path::FeatureCompoundPython"): PathLog.error(translate("Please select a Profile object")) return # everything ok! FreeCAD.ActiveDocument.openTransaction(translate("Create RampEntry Dress-up")) FreeCADGui.addModule("PathScripts.PathDressupRampEntry") FreeCADGui.addModule("PathScripts.PathUtils") FreeCADGui.doCommand('obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", "RampEntryDressup")') FreeCADGui.doCommand('dbo = PathScripts.PathDressupRampEntry.ObjectDressup(obj)') FreeCADGui.doCommand('base = FreeCAD.ActiveDocument.' + selection[0].Name) FreeCADGui.doCommand('job = PathScripts.PathUtils.findParentJob(base)') FreeCADGui.doCommand('obj.Base = base') FreeCADGui.doCommand('job.Proxy.addOperation(obj, base)') FreeCADGui.doCommand('PathScripts.PathDressupRampEntry.ViewProviderDressup(obj.ViewObject)') FreeCADGui.doCommand('Gui.ActiveDocument.getObject(base.Name).Visibility = False') FreeCADGui.doCommand('dbo.setup(obj)') 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_DressupDragKnife", "Please select one path object")+"\n") return if not selection[0].isDerivedFrom("Path::Feature"): FreeCAD.Console.PrintError( translate("Path_DressupDragKnife", "The selected object is not a path")+"\n") return if selection[0].isDerivedFrom("Path::FeatureCompoundPython"): FreeCAD.Console.PrintError( translate("Path_DressupDragKnife", "Please select a Path object")) return # everything ok! FreeCAD.ActiveDocument.openTransaction(translate("Path_DressupDragKnife", "Create Dress-up")) FreeCADGui.addModule("PathScripts.PathDressupDragknife") FreeCADGui.addModule("PathScripts.PathUtils") FreeCADGui.doCommand('obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython","DragknifeDressup")') FreeCADGui.doCommand('PathScripts.PathDressupDragknife.ObjectDressup(obj)') FreeCADGui.doCommand('base = FreeCAD.ActiveDocument.' + selection[0].Name) FreeCADGui.doCommand('job = PathScripts.PathUtils.findParentJob(base)') FreeCADGui.doCommand('obj.Base = base') FreeCADGui.doCommand('job.Proxy.addOperation(obj, base)') FreeCADGui.doCommand('PathScripts.PathDressupDragknife.ViewProviderDressup(obj.ViewObject)') FreeCADGui.doCommand('Gui.ActiveDocument.getObject(base.Name).Visibility = False') FreeCADGui.doCommand('obj.filterangle = 20') FreeCADGui.doCommand('obj.offset = 2') FreeCADGui.doCommand('obj.pivotheight = 4') 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("PathDressup_Dogbone", "Please select one path object\n")) return baseObject = selection[0] if not baseObject.isDerivedFrom("Path::Feature"): FreeCAD.Console.PrintError(translate("PathDressup_Dogbone", "The selected object is not a path\n")) return if baseObject.isDerivedFrom("Path::FeatureCompoundPython"): FreeCAD.Console.PrintError(translate("PathDressup_Dogbone", "Please select a Profile or Dogbone Dressup object")) return if not hasattr(baseObject, "Side"): FreeCAD.Console.PrintError(translate("PathDressup_Dogbone", "Please select a Profile or Dogbone Dressup object")) return # everything ok! FreeCAD.ActiveDocument.openTransaction(translate("PathDressup_Dogbone", "Create Dogbone Dress-up")) FreeCADGui.addModule("PathScripts.PathDressupDogbone") FreeCADGui.addModule("PathScripts.PathUtils") FreeCADGui.doCommand('obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", "DogboneDressup")') FreeCADGui.doCommand('dbo = PathScripts.PathDressupDogbone.ObjectDressup(obj)') FreeCADGui.doCommand('obj.Base = FreeCAD.ActiveDocument.' + baseObject.Name) FreeCADGui.doCommand('PathScripts.PathDressupDogbone.ViewProviderDressup(obj.ViewObject)') FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)') FreeCADGui.doCommand('obj.Base.ViewObject.Visibility = False') FreeCADGui.doCommand('dbo.setup(obj)') FreeCAD.ActiveDocument.commitTransaction() 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): sel = FreeCADGui.Selection.getSelection() ok = False if (len(sel) == 1): if Draft.getType(sel[0]) in ["Cell","Site","Floor"]: FreeCAD.ActiveDocument.openTransaction(translate("Arch","Type conversion")) FreeCADGui.addModule("Arch") FreeCADGui.doCommand("obj = Arch.makeBuilding()") FreeCADGui.doCommand("Arch.copyProperties(FreeCAD.ActiveDocument."+sel[0].Name+",obj)") FreeCADGui.doCommand('FreeCAD.ActiveDocument.removeObject("'+sel[0].Name+'")') FreeCAD.ActiveDocument.commitTransaction() ok = True if not ok: FreeCAD.ActiveDocument.openTransaction(translate("Arch"," Create Building")) ss = "[" for o in sel: if len(ss) > 1: ss += "," ss += "FreeCAD.ActiveDocument."+o.Name ss += "]" FreeCAD.ActiveDocument.openTransaction(translate("Arch","Floor")) FreeCADGui.addModule("Arch") FreeCADGui.doCommand("Arch.makeBuilding("+ss+")") FreeCAD.ActiveDocument.commitTransaction() 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 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): zbottom = 0.0 ztop = 10.0 # if everything is ok, execute and register the transaction in the undo/redo stack FreeCAD.ActiveDocument.openTransaction(translate("PathPocket", "Create Pocket")) FreeCADGui.addModule("PathScripts.PathPocket") FreeCADGui.doCommand('obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", "Pocket")') FreeCADGui.doCommand('PathScripts.PathPocket.ObjectPocket(obj)') FreeCADGui.doCommand('obj.Active = True') FreeCADGui.doCommand('PathScripts.PathPocket.ViewProviderPocket(obj.ViewObject)') FreeCADGui.doCommand('from PathScripts import PathUtils') FreeCADGui.doCommand('obj.Algorithm = "libarea"') FreeCADGui.doCommand('obj.StepOver = 100') FreeCADGui.doCommand('obj.ClearanceHeight = 10') # + str(bb.ZMax + 2.0)) FreeCADGui.doCommand('obj.StepDown = 1.0') FreeCADGui.doCommand('obj.StartDepth = ' + str(ztop)) FreeCADGui.doCommand('obj.FinalDepth =' + str(zbottom)) FreeCADGui.doCommand('obj.ZigZagAngle = 45') FreeCADGui.doCommand('obj.UseEntry = False') FreeCADGui.doCommand('obj.RampAngle = 3.0') FreeCADGui.doCommand('obj.RampSize = 0.75') FreeCADGui.doCommand('obj.HelixSize = 0.75') FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)') FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() FreeCADGui.doCommand('obj.ViewObject.startEditing()')
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 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): # 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 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 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): 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 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 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): # 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 Activated(self): FreeCADGui.addModule("Arch") FreeCADGui.doCommandGui("Arch.survey()")
def Activated(self): FreeCADGui.addModule("MaterialEditor") FreeCADGui.doCommand("MaterialEditor.openEditor()")
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create SolverZ88") FreeCADGui.addModule("FemSolverZ88") FreeCADGui.doCommand( "FemGui.getActiveAnalysis().Member = FemGui.getActiveAnalysis().Member + [FemSolverZ88.makeFemSolverZ88()]" )
def trimObject(self): """Trim the actual object.""" import Part if self.extrudeMode: delta = self.extrude(self.shift, real=True) # print("delta", delta) self.doc.openTransaction("Extrude") Gui.addModule("Draft") obj = Draft.extrude(self.obj, delta, solid=True) self.doc.commitTransaction() self.obj = obj else: edges = self.redraw(self.point, self.snapped, self.shift, self.alt, real=True) newshape = Part.Wire(edges) self.doc.openTransaction("Trim/extend") if utils.getType(self.obj) in ["Wire", "BSpline"]: p = [] if self.placement: invpl = self.placement.inverse() for v in newshape.Vertexes: np = v.Point if self.placement: np = invpl.multVec(np) p.append(np) self.obj.Points = p elif utils.getType(self.obj) == "Part::Line": p = [] if self.placement: invpl = self.placement.inverse() for v in newshape.Vertexes: np = v.Point if self.placement: np = invpl.multVec(np) p.append(np) if ((p[0].x == self.obj.X1) and (p[0].y == self.obj.Y1) and (p[0].z == self.obj.Z1)): self.obj.X2 = p[-1].x self.obj.Y2 = p[-1].y self.obj.Z2 = p[-1].z elif ((p[-1].x == self.obj.X1) and (p[-1].y == self.obj.Y1) and (p[-1].z == self.obj.Z1)): self.obj.X2 = p[0].x self.obj.Y2 = p[0].y self.obj.Z2 = p[0].z elif ((p[0].x == self.obj.X2) and (p[0].y == self.obj.Y2) and (p[0].z == self.obj.Z2)): self.obj.X1 = p[-1].x self.obj.Y1 = p[-1].y self.obj.Z1 = p[-1].z else: self.obj.X1 = p[0].x self.obj.Y1 = p[0].y self.obj.Z1 = p[0].z elif utils.getType(self.obj) == "Circle": angles = self.ghost[0].getAngles() # print("original", self.obj.FirstAngle," ",self.obj.LastAngle) # print("new", angles) if angles[0] > angles[1]: angles = (angles[1], angles[0]) self.obj.FirstAngle = angles[0] self.obj.LastAngle = angles[1] else: self.obj.Shape = newshape self.doc.commitTransaction() self.doc.recompute() for g in self.ghost: g.off()
def drawArc(self): """Actually draw the arc object.""" rot, sup, pts, fil = self.getStrings() if self.closedCircle: try: # The command to run is built as a series of text strings # to be committed through the `draftutils.todo.ToDo` class. if utils.getParam("UsePartPrimitives", False): # Insert a Part::Primitive object _base = DraftVecUtils.toString(self.center) _cmd = 'FreeCAD.ActiveDocument.' _cmd += 'addObject("Part::Circle", "Circle")' _cmd_list = [ 'circle = ' + _cmd, 'circle.Radius = ' + str(self.rad), 'pl = FreeCAD.Placement()', 'pl.Rotation.Q = ' + rot, 'pl.Base = ' + _base, 'circle.Placement = pl', 'Draft.autogroup(circle)', 'FreeCAD.ActiveDocument.recompute()' ] self.commit(translate("draft", "Create Circle (Part)"), _cmd_list) else: # Insert a Draft circle Gui.addModule("Draft") _base = DraftVecUtils.toString(self.center) _cmd = 'Draft.makeCircle' _cmd += '(' _cmd += 'radius=' + str(self.rad) + ', ' _cmd += 'placement=pl, ' _cmd += 'face=' + fil + ', ' _cmd += 'support=' + sup _cmd += ')' _cmd_list = [ 'pl=FreeCAD.Placement()', 'pl.Rotation.Q=' + rot, 'pl.Base=' + _base, 'circle = ' + _cmd, 'Draft.autogroup(circle)', 'FreeCAD.ActiveDocument.recompute()' ] self.commit(translate("draft", "Create Circle"), _cmd_list) except Exception: _err("Draft: error delaying commit") else: # Not a closed circle, therefore a circular arc sta = math.degrees(self.firstangle) end = math.degrees(self.firstangle + self.angle) if end < sta: sta, end = end, sta while True: if sta > 360: sta = sta - 360 elif end > 360: end = end - 360 else: break try: Gui.addModule("Draft") if utils.getParam("UsePartPrimitives", False): # Insert a Part::Primitive object _base = DraftVecUtils.toString(self.center) _cmd = 'FreeCAD.ActiveDocument.' _cmd += 'addObject("Part::Circle", "Circle")' _cmd_list = [ 'circle = ' + _cmd, 'circle.Radius = ' + str(self.rad), 'circle.Angle0 = ' + str(sta), 'circle.Angle1 = ' + str(end), 'pl = FreeCAD.Placement()', 'pl.Rotation.Q = ' + rot, 'pl.Base = ' + _base, 'circle.Placement = pl', 'Draft.autogroup(circle)', 'FreeCAD.ActiveDocument.recompute()' ] self.commit(translate("draft", "Create Arc (Part)"), _cmd_list) else: # Insert a Draft circle _base = DraftVecUtils.toString(self.center) _cmd = 'Draft.makeCircle' _cmd += '(' _cmd += 'radius=' + str(self.rad) + ', ' _cmd += 'placement=pl, ' _cmd += 'face=' + fil + ', ' _cmd += 'startangle=' + str(sta) + ', ' _cmd += 'endangle=' + str(end) + ', ' _cmd += 'support=' + sup _cmd += ')' _cmd_list = [ 'pl = FreeCAD.Placement()', 'pl.Rotation.Q = ' + rot, 'pl.Base = ' + _base, 'circle = ' + _cmd, 'Draft.autogroup(circle)', 'FreeCAD.ActiveDocument.recompute()' ] self.commit(translate("draft", "Create Arc"), _cmd_list) except Exception: _err("Draft: error delaying commit") # Finalize full circle or cirular arc self.finish(cont=True)
def Activated(self): # check that the selection contains exactly what we want selection = FreeCADGui.Selection.getSelectionEx() if len(selection) != 1: FreeCAD.Console.PrintError( translate( "Path_Pocket", "Please select an edges loop from one object, or a single face\n" )) return if len(selection[0].SubObjects) == 0: FreeCAD.Console.PrintError( translate( "Path_Pocket", "Please select an edges loop from one object, or a single face\n" )) return for s in selection[0].SubObjects: if s.ShapeType != "Edge": if (s.ShapeType != "Face") or (len(selection[0].SubObjects) != 1): FreeCAD.Console.PrintError( translate( "Path_Pocket", "Please select only edges or a single face\n")) return if selection[0].SubObjects[0].ShapeType == "Edge": try: import Part w = Part.Wire(selection[0].SubObjects) except: FreeCAD.Console.PrintError( translate("Path_Pocket", "The selected edges don't form a loop\n")) return # if everything is ok, execute and register the transaction in the undo/redo stack FreeCAD.ActiveDocument.openTransaction( translate("Path_Pocket", "Create Pocket")) FreeCADGui.addModule("PathScripts.PathPocket") FreeCADGui.doCommand('prjexists = False') FreeCADGui.doCommand( 'obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython","Pocket")' ) FreeCADGui.doCommand('PathScripts.PathPocket.ObjectPocket(obj)') FreeCADGui.doCommand( 'PathScripts.PathPocket.ViewProviderPocket(obj.ViewObject)') subs = "[" for s in selection[0].SubElementNames: subs += '"' + s + '",' subs += "]" FreeCADGui.doCommand('obj.Base = (FreeCAD.ActiveDocument.' + selection[0].ObjectName + ',' + subs + ')') FreeCADGui.doCommand('obj.Active = True') snippet = ''' from PathScripts import PathUtils PathUtils.addToProject(obj) ZMax = obj.Base[0].Shape.BoundBox.ZMax ZMin = obj.Base[0].Shape.BoundBox.ZMin obj.StepDown = 1.0 obj.StartDepth = ZMax obj.FinalDepth = ZMin obj.ClearanceHeight = ZMax + 5.0 ''' FreeCADGui.doCommand(snippet) FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute()
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 FemElementGeometry2D") FreeCADGui.addModule("ObjectsFem") FreeCADGui.doCommand( "FemGui.getActiveAnalysis().Member = FemGui.getActiveAnalysis().Member + [ObjectsFem.makeElementGeometry2D()]" )
def doStretch(self): """Do the actual stretching once the points are selected.""" commitops = [] if self.displacement: if self.displacement.Length > 0: _doc = "FreeCAD.ActiveDocument." # print("displacement: ", self.displacement) # TODO: break this section into individual functions # depending on the type of object (wire, curve, sketch, # rectangle, etc.) that is selected, and use variables # with common strings to avoid repeating # the same information every time, for example, the `_doc` # variable. # This is necessary to reduce the number of indentation levels # and make the code easier to read. for ops in self.ops: tp = utils.getType(ops[0]) _rot = ops[0].Placement.Rotation localdisp = _rot.inverted().multVec(self.displacement) if tp in ["Wire", "BSpline", "BezCurve"]: pts = [] for i in range(len(ops[1])): if ops[1][i] is False: pts.append(ops[0].Points[i]) else: pts.append(ops[0].Points[i].add(localdisp)) pts = str(pts).replace("Vector ", "FreeCAD.Vector") _cmd = _doc + ops[0].Name + ".Points=" + pts commitops.append(_cmd) elif tp in ["Sketch"]: baseverts = [ ops[0].Shape.Vertexes[i].Point for i in range(len(ops[1])) if ops[1][i] ] for i in range(ops[0].GeometryCount): j = 0 while True: try: p = ops[0].getPoint(i, j) except ValueError: break else: p = ops[0].Placement.multVec(p) r = None for bv in baseverts: if DraftVecUtils.isNull(p.sub(bv)): _cmd = _doc _cmd += ops[0].Name _cmd += ".movePoint" _cmd += "(" _cmd += str(i) + ", " _cmd += str(j) + ", " _cmd += "FreeCAD." + str( localdisp) + ", " _cmd += "True" _cmd += ")" commitops.append(_cmd) r = bv break if r: baseverts.remove(r) j += 1 elif tp in ["Rectangle"]: p1 = App.Vector(0, 0, 0) p2 = App.Vector(ops[0].Length.Value, 0, 0) p3 = App.Vector(ops[0].Length.Value, ops[0].Height.Value, 0) p4 = App.Vector(0, ops[0].Height.Value, 0) if ops[1] == [False, True, True, False]: optype = 1 elif ops[1] == [False, False, True, True]: optype = 2 elif ops[1] == [True, False, False, True]: optype = 3 elif ops[1] == [True, True, False, False]: optype = 4 else: optype = 0 # print("length:", ops[0].Length, # "height:", ops[0].Height, # " - ", ops[1], # " - ", self.displacement) done = False if optype > 0: v1 = ops[0].Placement.multVec(p2).sub( ops[0].Placement.multVec(p1)) a1 = round(self.displacement.getAngle(v1), 4) v2 = ops[0].Placement.multVec(p4).sub( ops[0].Placement.multVec(p1)) a2 = round(self.displacement.getAngle(v2), 4) # check if the displacement is along one # of the rectangle directions if a1 == 0: # 0 degrees if optype == 1: if ops[0].Length.Value >= 0: d = ops[ 0].Length.Value + self.displacement.Length else: d = ops[ 0].Length.Value - self.displacement.Length _cmd = _doc _cmd += ops[0].Name + ".Length=" + str(d) commitops.append(_cmd) done = True elif optype == 3: if ops[0].Length.Value >= 0: d = ops[ 0].Length.Value - self.displacement.Length else: d = ops[ 0].Length.Value + self.displacement.Length _cmd = _doc + ops[0].Name _cmd += ".Length=" + str(d) _pl = _doc + ops[0].Name _pl += ".Placement.Base=FreeCAD." _pl += str(ops[0].Placement.Base.add( self.displacement)) commitops.append(_cmd) commitops.append(_pl) done = True elif a1 == 3.1416: # pi radians, 180 degrees if optype == 1: if ops[0].Length.Value >= 0: d = ops[ 0].Length.Value - self.displacement.Length else: d = ops[ 0].Length.Value + self.displacement.Length _cmd = _doc + ops[0].Name _cmd += ".Length=" + str(d) commitops.append(_cmd) done = True elif optype == 3: if ops[0].Length.Value >= 0: d = ops[ 0].Length.Value + self.displacement.Length else: d = ops[ 0].Length.Value - self.displacement.Length _cmd = _doc + ops[0].Name _cmd += ".Length=" + str(d) _pl = _doc + ops[0].Name _pl += ".Placement.Base=FreeCAD." _pl += str(ops[0].Placement.Base.add( self.displacement)) commitops.append(_cmd) commitops.append(_pl) done = True elif a2 == 0: # 0 degrees if optype == 2: if ops[0].Height.Value >= 0: d = ops[ 0].Height.Value + self.displacement.Length else: d = ops[ 0].Height.Value - self.displacement.Length _cmd = _doc + ops[0].Name _cmd += ".Height=" + str(d) commitops.append(_cmd) done = True elif optype == 4: if ops[0].Height.Value >= 0: d = ops[ 0].Height.Value - self.displacement.Length else: d = ops[ 0].Height.Value + self.displacement.Length _cmd = _doc + ops[0].Name _cmd += ".Height=" + str(d) _pl = _doc + ops[0].Name _pl += ".Placement.Base=FreeCAD." _pl += str(ops[0].Placement.Base.add( self.displacement)) commitops.append(_cmd) commitops.append(_pl) done = True elif a2 == 3.1416: # pi radians, 180 degrees if optype == 2: if ops[0].Height.Value >= 0: d = ops[ 0].Height.Value - self.displacement.Length else: d = ops[ 0].Height.Value + self.displacement.Length _cmd = _doc + ops[0].Name _cmd += ".Height=" + str(d) commitops.append(_cmd) done = True elif optype == 4: if ops[0].Height.Value >= 0: d = ops[ 0].Height.Value + self.displacement.Length else: d = ops[ 0].Height.Value - self.displacement.Length _cmd = _doc + ops[0].Name _cmd += ".Height=" + str(d) _pl = _doc + ops[0].Name _pl += ".Placement.Base=FreeCAD." _pl += str(ops[0].Placement.Base.add( self.displacement)) commitops.append(_cmd) commitops.append(_pl) done = True if not done: # otherwise create a wire copy and stretch it instead _msg( translate("draft", "Turning one Rectangle into a Wire")) pts = [] vts = ops[0].Shape.Vertexes for i in range(4): if ops[1][i] == False: pts.append(vts[i].Point) else: pts.append(vts[i].Point.add( self.displacement)) pts = str(pts).replace("Vector ", "FreeCAD.Vector") _cmd = "Draft.makeWire" _cmd += "(" + pts + ", closed=True)" _format = "Draft.formatObject" _format += "(w, " _format += _doc + ops[0].Name _format += ")" _hide = _doc + ops[0].Name + ".ViewObject.hide()" commitops.append("w = " + _cmd) commitops.append(_format) commitops.append(_hide) else: _pl = _doc + ops[0].Name _pl += ".Placement.Base=FreeCAD." _pl += str(ops[0].Placement.Base.add( self.displacement)) commitops.append(_pl) if commitops: commitops.append("FreeCAD.ActiveDocument.recompute()") Gui.addModule("Draft") self.commit(translate("draft", "Stretch"), commitops) self.finish()
def Activated(self): PathLog.track() FreeCAD.ActiveDocument.openTransaction( translate("Path_Post", "Post Process the Selected path(s)")) FreeCADGui.addModule("PathScripts.PathPost") # Attempt to figure out what the user wants to post-process # If a job is selected, post that. # If there's only one job in a document, post it. # If a user has selected a subobject of a job, post the job. # If multiple jobs and can't guess, ask them. selected = FreeCADGui.Selection.getSelectionEx() if len(selected) > 1: FreeCAD.Console.PrintError( "Please select a single job or other path object\n") return elif len(selected) == 1: sel = selected[0].Object if sel.Name[:3] == "Job": job = sel elif hasattr(sel, "Path"): try: job = PathUtils.findParentJob(sel) except Exception: # pylint: disable=broad-except job = None else: job = None if job is None: targetlist = [] for o in FreeCAD.ActiveDocument.Objects: if hasattr(o, "Proxy"): if isinstance(o.Proxy, PathJob.ObjectJob): targetlist.append(o.Label) PathLog.debug("Possible post objects: {}".format(targetlist)) if len(targetlist) > 1: form = FreeCADGui.PySideUic.loadUi(":/panels/DlgJobChooser.ui") form.cboProject.addItems(targetlist) r = form.exec_() if r is False: return else: jobname = form.cboProject.currentText() else: jobname = targetlist[0] job = FreeCAD.ActiveDocument.getObject(jobname) PathLog.debug("about to postprocess job: {}".format(job.Name)) # Build up an ordered list of operations and tool changes. # Then post-the ordered list if hasattr(job, "Fixtures"): wcslist = job.Fixtures else: wcslist = ['G54'] if hasattr(job, "OrderOutputBy"): orderby = job.OrderOutputBy else: orderby = "Operation" if hasattr(job, "SplitOutput"): split = job.SplitOutput else: split = False postlist = [] if orderby == 'Fixture': PathLog.debug("Ordering by Fixture") # Order by fixture means all operations and tool changes will be completed in one # fixture before moving to the next. currTool = None for f in wcslist: # create an object to serve as the fixture path fobj = _TempObject() c1 = Path.Command(f) c2 = Path.Command("G0 Z" + str(job.Stock.Shape.BoundBox.ZMax)) fobj.Path = Path.Path([c1, c2]) fobj.InList.append(job) sublist = [fobj] # Now generate the gcode for obj in job.Operations.Group: tc = PathUtil.toolControllerForOp(obj) if tc is not None: if tc.ToolNumber != currTool: sublist.append(tc) PathLog.debug("Appending TC: {}".format(tc.Name)) currTool = tc.ToolNumber sublist.append(obj) postlist.append(sublist) elif orderby == 'Tool': PathLog.debug("Ordering by Tool") # Order by tool means tool changes are minimized. # all operations with the current tool are processed in the current # fixture before moving to the next fixture. currTool = None fixturelist = [] for f in wcslist: # create an object to serve as the fixture path fobj = _TempObject() c1 = Path.Command(f) c2 = Path.Command("G0 Z" + str(job.Stock.Shape.BoundBox.ZMax)) fobj.Path = Path.Path([c1, c2]) fobj.InList.append(job) fixturelist.append(fobj) # Now generate the gcode curlist = [] # list of ops for tool, will repeat for each fixture sublist = [] # list of ops for output splitting for idx, obj in enumerate(job.Operations.Group): tc = PathUtil.toolControllerForOp(obj) if tc is None or tc.ToolNumber == currTool: curlist.append(obj) elif tc.ToolNumber != currTool and currTool is None: # first TC sublist.append(tc) curlist.append(obj) currTool = tc.ToolNumber elif tc.ToolNumber != currTool and currTool is not None: # TC for fixture in fixturelist: sublist.append(fixture) sublist.extend(curlist) postlist.append(sublist) sublist = [tc] curlist = [obj] currTool = tc.ToolNumber if idx == len(job.Operations.Group) - 1: # Last operation. for fixture in fixturelist: sublist.append(fixture) sublist.extend(curlist) postlist.append(sublist) elif orderby == 'Operation': PathLog.debug("Ordering by Operation") # Order by operation means ops are done in each fixture in # sequence. currTool = None fixturelist = [] for f in wcslist: # create an object to serve as the fixture path fobj = _TempObject() c1 = Path.Command(f) c2 = Path.Command("G0 Z" + str(job.Stock.Shape.BoundBox.ZMax)) fobj.Path = Path.Path([c1, c2]) fobj.InList.append(job) fixturelist.append(fobj) # Now generate the gcode for obj in job.Operations.Group: sublist = [] PathLog.debug("obj: {}".format(obj.Name)) for fixture in fixturelist: sublist.append(fixture) tc = PathUtil.toolControllerForOp(obj) if tc is not None: if tc.ToolNumber != currTool: sublist.append(tc) currTool = tc.ToolNumber sublist.append(obj) postlist.append(sublist) fail = True rc = '' # pylint: disable=unused-variable if split: for slist in postlist: (fail, rc) = self.exportObjectsWith(slist, job) else: finalpostlist = [item for slist in postlist for item in slist] (fail, rc) = self.exportObjectsWith(finalpostlist, job) self.subpart = 1 if fail: FreeCAD.ActiveDocument.abortTransaction() else: FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute()
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create FemShellThickness") FreeCADGui.addModule("ObjectsFem") FreeCADGui.doCommand( "FemGui.getActiveAnalysis().Member = FemGui.getActiveAnalysis().Member + [ObjectsFem.makeShellThickness()]" )
def Activated(self): layer = App.ActiveDocument.getObjectsByLabel("IfcSpaceBoundaries")[0] Gui.addModule("envis.functions.bruttofacemodel") Gui.doCommand("bruttofacemodel = envis.functions.bruttofacemodel") Gui.doCommand("_layer_ = App.ActiveDocument." + layer.Name) Gui.doCommand("bruttofacemodel.createModel(_layer_)")
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create FemConstraintElectrostaticPotential") FreeCADGui.addModule("ObjectsFem") FreeCADGui.doCommand("FemGui.getActiveAnalysis().addObject(ObjectsFem.makeConstraintElectrostaticPotential(FreeCAD.ActiveDocument))")
def getPoint(self,point=None,obj=None): "this function is called by the snapper when it has a 3D point" if self.modeb.isChecked() and (self.bpoint == None): self.bpoint = point FreeCADGui.Snapper.getPoint(callback=self.getPoint,movecallback=self.update,extradlg=[self.taskbox(),self.precast.form,self.dents.form]) return self.tracker.finalize() if point == None: return FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Structure")) FreeCADGui.addModule("Arch") if self.Profile is not None: if "Precast" in self.Profile: # precast concrete args = self.precast.getValues() args["PrecastType"] = self.Profile.split("_")[1] args["Length"] = self.Length args["Width"] = self.Width args["Height"] = self.Height argstring = "" # fix for precast placement, since their (0,0) point is the lower left corner point = FreeCAD.Vector(point.x-self.Length/2,point.y-self.Width/2,point.z) for pair in args.items(): argstring += pair[0].lower() + "=" if isinstance(pair[1],str): argstring += '"' + pair[1] + '",' else: argstring += str(pair[1]) + "," FreeCADGui.addModule("ArchPrecast") FreeCADGui.doCommand("s = ArchPrecast.makePrecast("+argstring+")") else: # metal profile FreeCADGui.doCommand('p = Arch.makeProfile('+str(self.Profile)+')') if self.Length == self.Profile[4]: # vertical FreeCADGui.doCommand('s = Arch.makeStructure(p,height='+str(self.Height)+')') else: # horizontal FreeCADGui.doCommand('s = Arch.makeStructure(p,height='+str(self.Length)+')') if not self.bmode: FreeCADGui.doCommand('s.Placement.Rotation = FreeCAD.Rotation(-0.5,0.5,-0.5,0.5)') FreeCADGui.doCommand('s.Profile = "'+self.Profile[2]+'"') else : FreeCADGui.doCommand('s = Arch.makeStructure(length='+str(self.Length)+',width='+str(self.Width)+',height='+str(self.Height)+')') if self.bmode and self.bpoint: FreeCADGui.doCommand('s.Placement.Base = '+DraftVecUtils.toString(self.bpoint)) else: FreeCADGui.doCommand('s.Placement.Base = '+DraftVecUtils.toString(point)) if self.bmode and self.bpoint: rot = FreeCAD.Rotation(Vector(1,0,0),(point.sub(self.bpoint)).normalize()) FreeCADGui.doCommand('s.Placement.Rotation=FreeCAD.Rotation'+str(rot.Q)) else: FreeCADGui.doCommand('s.Placement.Rotation=s.Placement.Rotation.multiply(FreeCAD.DraftWorkingPlane.getRotation().Rotation)') FreeCADGui.addModule("Draft") FreeCADGui.doCommand("Draft.autogroup(s)") FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() if self.continueCmd: self.Activated()
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create SolverZ88") FreeCADGui.addModule("ObjectsFem") FreeCADGui.doCommand("FemGui.getActiveAnalysis().addObject(ObjectsFem.makeSolverZ88(FreeCAD.ActiveDocument))")
def Activated(self): PathLog.track() FreeCAD.ActiveDocument.openTransaction( translate("Path_Post", "Post Process the Selected path(s)")) FreeCADGui.addModule("PathScripts.PathPost") # Attempt to figure out what the user wants to post-process # If a job is selected, post that. # If there's only one job in a document, post it. # If a user has selected a subobject of a job, post the job. # If multiple jobs and can't guess, ask them. selected = FreeCADGui.Selection.getSelectionEx() if len(selected) > 1: FreeCAD.Console.PrintError("Please select a single job or other path object\n") return elif len(selected) == 1: sel = selected[0].Object if sel.Name[:3] == "Job": job = sel elif hasattr(sel, "Path"): try: job = PathUtils.findParentJob(sel) except: job = None else: job = None if job is None: targetlist = [] for o in FreeCAD.ActiveDocument.Objects: if hasattr(o, "Proxy"): if isinstance(o.Proxy, PathJob.ObjectJob): targetlist.append(o.Label) PathLog.debug("Possible post objects: {}".format(targetlist)) if len(targetlist) > 1: form = FreeCADGui.PySideUic.loadUi(":/panels/DlgJobChooser.ui") form.cboProject.addItems(targetlist) r = form.exec_() if r is False: return else: jobname = form.cboProject.currentText() else: jobname = targetlist[0] job = FreeCAD.ActiveDocument.getObject(jobname) PathLog.debug("about to postprocess job: {}".format(job.Name)) # Build up an ordered list of operations and tool changes. # Then post-the ordered list postlist = [] currTool = None for obj in job.Operations.Group: PathLog.debug("obj: {}".format(obj.Name)) tc = PathUtil.toolControllerForOp(obj) if tc is not None: if tc.ToolNumber != currTool: postlist.append(tc) postlist.append(obj) fail = True rc = '' (fail, rc) = self.exportObjectsWith(postlist, job) if fail: FreeCAD.ActiveDocument.abortTransaction() else: FreeCAD.ActiveDocument.commitTransaction() 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.Selection.clearSelection()
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create FemConstraintBodyHeatSource") FreeCADGui.addModule("ObjectsFem") FreeCADGui.doCommand("FemGui.getActiveAnalysis().addObject(ObjectsFem.makeConstraintBodyHeatSource(FreeCAD.ActiveDocument))")
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)")
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 Activated(self): FreeCAD.ActiveDocument.openTransaction("Create FemElementGeometry1D") FreeCADGui.addModule("ObjectsFem") FreeCADGui.doCommand("FemGui.getActiveAnalysis().addObject(ObjectsFem.makeElementGeometry1D(FreeCAD.ActiveDocument))")
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Clear FEM mesh") FreeCADGui.addModule("Fem") FreeCADGui.doCommand("App.ActiveDocument." + self.selobj.Name + ".FemMesh = Fem.FemMesh()") FreeCADGui.doCommand("App.ActiveDocument.recompute()") FreeCADGui.Selection.clearSelection()
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.width(self.Width) self.tracker.height(self.Height) 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.LineSegment( FreeCAD.DraftWorkingPlane.getLocalCoords(self.points[0]), FreeCAD.DraftWorkingPlane.getLocalCoords(self.points[1])) self.tracker.finalize() FreeCAD.ActiveDocument.openTransaction( translate("Arch", "Create Wall")) FreeCADGui.addModule("Arch") FreeCADGui.doCommand('import Part') FreeCADGui.doCommand('trace=Part.LineSegment(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 FemEquationFluxsolver") FreeCADGui.addModule("ObjectsFem") FreeCADGui.doCommand("ObjectsFem.makeEquationFluxsolver(FreeCAD.ActiveDocument, FreeCAD.ActiveDocument." + self.selobj.Name + ")") FreeCADGui.Selection.clearSelection()
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create involute gear") FreeCADGui.addModule("InvoluteGearFeature") FreeCADGui.doCommand("InvoluteGearFeature.makeInvoluteGear('InvoluteGear')") FreeCADGui.doCommand("Gui.activeDocument().setEdit(App.ActiveDocument.ActiveObject.Name,0)")
def Activated(self): FreeCAD.ActiveDocument.openTransaction("Create FemConstraintInitialFlowVelocity") FreeCADGui.addModule("ObjectsFem") FreeCADGui.doCommand("FemGui.getActiveAnalysis().addObject(ObjectsFem.makeConstraintInitialFlowVelocity(FreeCAD.ActiveDocument))")
def Activated(self): import Path from PathScripts import PathUtils,PathProfile,PathProject prjexists = False selection = PathSelection.multiSelect() if not selection: return # if everything is ok, execute and register the transaction in the undo/redo stack FreeCAD.ActiveDocument.openTransaction(translate("Path_Profile","Create Profile")) FreeCADGui.addModule("PathScripts.PathProfile") obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython","Profile") PathProfile.ObjectProfile(obj) PathProfile.ViewProviderProfile(obj.ViewObject) obj.Base = (FreeCAD.ActiveDocument.getObject(selection['objname'])) if selection['facenames']: #FreeCAD.Console.PrintMessage('There are edges selected\n') obj.Face1 = (FreeCAD.ActiveDocument.getObject(selection['objname']),selection['facenames'][0]) if len(selection['facenames'])>1: obj.Face2 = (FreeCAD.ActiveDocument.getObject(selection['objname']),selection['facenames'][-1]) if selection['edgenames']: #FreeCAD.Console.PrintMessage('There are edges selected\n') obj.Edge1 =(FreeCAD.ActiveDocument.getObject(selection['objname']),(selection['edgenames'][0])) if len(selection['edgenames'])>1: obj.Edge2 =(FreeCAD.ActiveDocument.getObject(selection['objname']),(selection['edgenames'][-1])) if selection['pointlist']: FreeCADGui.doCommand('from FreeCAD import Vector') stptX, stptY, stptZ = selection['pointlist'][0].X, selection['pointlist'][0].Y, selection['pointlist'][0].Z obj.StartPoint = Vector((stptX),(stptY),(stptZ)) if len(selection['pointlist'])>1: # we have more than one point so we have an end point endptX, endptY, endptZ = selection['pointlist'][-1].X, selection['pointlist'][-1].Y, selection['pointlist'][-1].Z obj.EndPoint = Vector(endptX,endptY,endptZ) if selection['pathwire'].isClosed(): obj.PathClosed = True if selection['clockwise']: obj.Side = "Left" obj.Direction = "CW" elif selection['clockwise'] == False: obj.Side = "Right" obj.Direction = "CCW" else: obj.Side = "On" obj.Direction = "CCW" obj.PathClosed = False ZMax = obj.Base[0].Shape.BoundBox.ZMax ZMin = obj.Base[0].Shape.BoundBox.ZMin obj.StepDown.Value = 1.0 obj.StartDepth.Value = ZMax- obj.StepDown.Value obj.FinalDepth.Value = ZMin-1.0 obj.ClearanceHeight.Value = ZMax + 5.0 obj.SegLen.Value = 0.5 obj.Active = True obj.ViewObject.ShowFirstRapid = False project = PathUtils.addToProject(obj) tl = PathUtils.changeTool(obj,project) if tl: obj.ToolNumber = tl FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute()
def createObject(self): "creates the final object in the current doc" FreeCADGui.addModule("Draft") pl = FreeCAD.Placement() p1 = self.node[0] p3 = self.node[-1] diagonal = p3.sub(p1) p2 = p1.add( DraftTools.DraftVecUtils.project(diagonal, DraftTools.plane.v)) p4 = p1.add( DraftTools.DraftVecUtils.project(diagonal, DraftTools.plane.u)) length = p4.sub(p1).Length height = p2.sub(p1).Length try: #Draw verical if height > length: length = height if p1.y < p3.y: if p1.x < p3.x: pl.Rotation = FreeCAD.Rotation(-90, 0, 0) base = p2 else: pl.Rotation = FreeCAD.Rotation(90, 0, 0) base = p1 print("p1<p3") else: if p1.x < p3.x: pl.Rotation = FreeCAD.Rotation(-90, 0, 0) base = p1 else: pl.Rotation = FreeCAD.Rotation(90, 0, 0) base = p2 #Draw horisontal else: if p1.x < p4.x: base = p1 else: base = p4 #lineDirection = Part.makeLine((p1.x, p1.y, p1.z), (p4.x, p4.y, p4.z)) #Part.show(lineDirection) #plane_line1 =Part.LineSegment(p1, p2) #plane_line2 =Part.LineSegment(p2, p3) #plane_line3 =Part.LineSegment(p3, p4) #plane_line4 =Part.LineSegment(p4, p1) #plane_shap =Part.Shape([plane_line1, plane_line2, plane_line3, plane_line4]) #plane_wire =Part.Wire(plane_shape.Edges) #plane_face =Part.Face(plane_wire) #Part.show(plane_face) pl.Base = base #pl.Rotation.Q = DraftTools.plane.getRotation().Rotation.Q if self.ShapeType == "TS35": self.CreateDINRail(length, pl) if self.ShapeType == "WD": self.CreateWiringDuct(length, pl) except: import traceback, sys exc_tb = sys.exc_traceback print("Failure in line: " + str(traceback.tb_lineno(exc_tb))) print("Draft: error delaying commit") self.finish(cont=True)
def Activated(self): FreeCADGui.addModule("Ui.CmdCalcVentHoles") FreeCADGui.doCommand("Ui.CmdCalcVentHoles.calcVentHoles()")
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.showDialog(ArchComponent.SelectionTaskPanel()) FreeCAD.ArchObserver = ArchComponent.ArchSelectionObserver( nextCommand="Arch_Rebar") FreeCADGui.Selection.addObserver(FreeCAD.ArchObserver)