def run(self): ret_code = 0 message = self.check_prerequisites() if not message: self.write_inp_file() from FreeCAD import Base progress_bar = Base.ProgressIndicator() progress_bar.start("Running CalculiX ccx...", 0) ret_code = self.start_ccx() self.finished.emit(ret_code) progress_bar.stop() if ret_code or self.ccx_stderr: FreeCAD.Console.PrintError( "CalculiX failed with exit code {}\n".format(ret_code)) FreeCAD.Console.PrintMessage( "--------start of stderr-------\n") FreeCAD.Console.PrintMessage(self.ccx_stderr) FreeCAD.Console.PrintMessage( "--------end of stderr---------\n") FreeCAD.Console.PrintMessage( "--------start of stdout-------\n") FreeCAD.Console.PrintMessage(self.ccx_stdout) self.has_for_nonpositive_jacobians() FreeCAD.Console.PrintMessage( "--------end of stdout---------\n") else: FreeCAD.Console.PrintMessage( "CalculiX finished without error\n") else: FreeCAD.Console.PrintError( "CalculiX was not started due to missing prerequisites:\n{}\n". format(message))
def run(self): global CANCEL_TASK CANCEL_TASK = False progress_bar = Base.ProgressIndicator() try: timers = [] processor = self.processor fp = self.fp processingSteps = processor.getProcessingSteps(fp) numberOfSteps = len(processingSteps) + 1 progress_bar.start(processor.description, numberOfSteps) actualStep = 1 lastReturnValue = None if self.startParameter != '<ignore>': lastReturnValue = self.startParameter for stepDescription, step in processingSteps: if CANCEL_TASK: print('Cancelling step %s' % (stepDescription)) break timers.append( Timer('%s (%s/%s)' % (stepDescription, actualStep, numberOfSteps))) lastReturnValue = self.executeStep(step, lastReturnValue) progress_bar.next() timers[-1].stop() actualStep += 1 if not CANCEL_TASK: timers.append( Timer('%s (%s/%s)' % ('Post Processing', actualStep, numberOfSteps))) processor.processingDone(fp, lastReturnValue) progress_bar.next() timers[-1].stop() FreeCAD.Console.PrintMessage( '%s took %.3f s' % (processor.description, computeOverallTime(timers))) except: raise finally: CANCEL_TASK = False self.running = False progress_bar.stop()
def run(self): if self.test_mode: FreeCAD.Console.PrintError( "CalculiX can not be run if test_mode is True.\n") return ret_code = 0 message = self.check_prerequisites() if not message: self.write_inp_file() from FreeCAD import Base progress_bar = Base.ProgressIndicator() progress_bar.start("Running CalculiX ccx...", 0) ret_code = self.start_ccx() self.finished.emit(ret_code) progress_bar.stop() if ret_code or self.ccx_stderr: if ret_code == 201 and self.solver.AnalysisType == 'check': FreeCAD.Console.PrintMessage( 'Workaround for wrong exit code for *NOANALYSIS check\n.' ) else: FreeCAD.Console.PrintError( "CalculiX failed with exit code {}\n".format(ret_code)) FreeCAD.Console.PrintMessage( "--------start of stderr-------\n") FreeCAD.Console.PrintMessage(self.ccx_stderr) FreeCAD.Console.PrintMessage( "--------end of stderr---------\n") FreeCAD.Console.PrintMessage( "--------start of stdout-------\n") FreeCAD.Console.PrintMessage(self.ccx_stdout) self.has_for_nonpositive_jacobians() FreeCAD.Console.PrintMessage( "--------end of stdout---------\n") else: FreeCAD.Console.PrintMessage( "CalculiX finished without error\n") else: FreeCAD.Console.PrintError( "CalculiX was not started due to missing prerequisites:\n{}\n". format(message))
def run(self): ret_code = 0 message = self.check_prerequisites() if not message: self.write_inp_file() from FreeCAD import Base progress_bar = Base.ProgressIndicator() progress_bar.start("Running CalculiX ccx...", 0) ret_code = self.start_ccx() self.finished.emit(ret_code) progress_bar.stop() else: print("Running analysis failed! {}".format(message)) if ret_code or self.ccx_stderr: print("Analysis failed with exit code {}".format(ret_code)) print("--------start of stderr-------") print(self.ccx_stderr) print("--------end of stderr---------") print("--------start of stdout-------") print(self.ccx_stdout) print("--------end of stdout---------")
def insert(filename, docname=None, preferences=None): """imports the contents of an IFC file in the given document""" import ifcopenshell from ifcopenshell import geom # reset global values global layers global materials global objects global adds global subs layers = {} materials = {} objects = {} adds = {} subs = {} # statistics starttime = time.time() # in seconds filesize = os.path.getsize(filename) * 0.000001 # in megabytes print("Opening", filename + ",", round(filesize, 2), "Mb") # setup ifcopenshell if not preferences: preferences = importIFC.getPreferences() settings = ifcopenshell.geom.settings() settings.set(settings.USE_BREP_DATA, True) settings.set(settings.SEW_SHELLS, True) settings.set(settings.USE_WORLD_COORDS, True) if preferences['SEPARATE_OPENINGS']: settings.set(settings.DISABLE_OPENING_SUBTRACTIONS, True) if preferences['SPLIT_LAYERS'] and hasattr(settings, "APPLY_LAYERSETS"): settings.set(settings.APPLY_LAYERSETS, True) # setup document if not FreeCAD.ActiveDocument: if not docname: docname = os.path.splitext(os.path.basename(filename))[0] doc = FreeCAD.newDocument(docname) doc.Label = docname FreeCAD.setActiveDocument(doc.Name) # open the file ifcfile = ifcopenshell.open(filename) progressbar = Base.ProgressIndicator() productscount = len(ifcfile.by_type("IfcProduct")) progressbar.start("Importing " + str(productscount) + " products...", productscount) cores = preferences["MULTICORE"] iterator = ifcopenshell.geom.iterator(settings, ifcfile, cores) iterator.initialize() count = 0 # process objects while True: item = iterator.get() if item: brep = item.geometry.brep_data ifcproduct = ifcfile.by_id(item.guid) obj = createProduct(ifcproduct, brep) progressbar.next(True) writeProgress(count, productscount, starttime) count += 1 if not iterator.next(): break # post-processing processRelationships() storeColorDict() # finished progressbar.stop() FreeCAD.ActiveDocument.recompute() endtime = round(time.time() - starttime, 1) fs = round(filesize, 1) ratio = int(endtime / filesize) endtime = "%02d:%02d" % (divmod(endtime, 60)) writeProgress() # this cleans the line print("Finished importing", fs, "Mb in", endtime, "s, or", ratio, "s/Mb") return FreeCAD.ActiveDocument
def create(self, data): """ Creating the Freecad elements inside a new document """ progress_bar = Base.ProgressIndicator() progress_bar.start("Running creating gear...", 0) FreeCAD.newDocument(data['name']) doc = FreeCAD.ActiveDocument App.activeDocument().addObject('PartDesign::Body', 'Gear') Gui.activeView().setActiveObject('pdbody', App.activeDocument().Gear) App.activeDocument().Gear.newObject('Sketcher::SketchObject', 'SketchGear') App.activeDocument().SketchGear.Support = ( App.activeDocument().XY_Plane, ['']) App.activeDocument().SketchGear.MapMode = 'FlatFace' App.activeDocument().SketchGear.Placement = App.Placement( App.Vector(0.000000, 0.000000, 0.000000), App.Rotation(0.000000, 0.000000, 0.000000, 1.000000)) App.activeDocument().recompute() self.create_gear(doc, data) d = float(self.shaft_diameter / 2) if self.shaft: if self.isCircle: if self.addKey: c = self.create_key(d, 0) keyLst = [] keyLst.append(Part.LineSegment(c[0], c[1])) keyLst.append(Part.LineSegment(c[1], c[2])) keyLst.append(Part.LineSegment(c[2], c[3])) doc.SketchGear.addGeometry(keyLst, False) doc.SketchGear.addGeometry( Part.ArcOfCircle(c[3], c[4], c[0])) else: doc.SketchGear.addGeometry( Part.Circle(App.Vector(0, 0, 0), App.Vector(0, 0, 1), d)) else: ProfileLib.RegularPolygon.makeRegularPolygon( 'SketchGear', 6, App.Vector(0.000000, 0.000000, 0), App.Vector(d, 0, 0), False) Gui.activeView().setActiveObject('pdbody', App.activeDocument().Gear) App.activeDocument().Gear.newObject("PartDesign::Pad", "Pad") App.activeDocument().Pad.Profile = App.activeDocument().SketchGear App.activeDocument().Pad.Profile = doc.SketchGear App.activeDocument().Pad.Length = float(self.hgear) App.activeDocument().recompute() Gui.activeDocument().hide("SketchGear") Gui.activeDocument().resetEdit() # Add base to the Gear if self.addBase: Gui.activeView().setActiveObject('pdbody', App.activeDocument().Gear) App.activeDocument().Gear.newObject('Sketcher::SketchObject', 'SketchBase') App.activeDocument().SketchBase.Support = ( App.activeDocument().XY_Plane, ['']) App.activeDocument().SketchBase.MapMode = 'FlatFace' App.activeDocument().SketchBase.Placement = App.Placement( App.Vector(0.000000, 0.000000, 0.000000), App.Rotation(0.000000, 0.000000, 0.000000, 1.000000)) App.activeDocument().recompute() doc.SketchBase.addGeometry( Part.Circle(App.Vector(0, 0, -float(self.base_height)), App.Vector(0, 0, 1), self.base_diameter)) if self.shaft: if self.isCircle: if self.addKey: c = self.create_key(d, -float(self.base_height)) keyLst = [] keyLst.append(Part.LineSegment(c[0], c[1])) keyLst.append(Part.LineSegment(c[1], c[2])) keyLst.append(Part.LineSegment(c[2], c[3])) doc.SketchBase.addGeometry(keyLst, False) doc.SketchBase.addGeometry( Part.ArcOfCircle(c[3], c[4], c[0])) else: doc.SketchBase.addGeometry( Part.Circle(App.Vector(0, 0, 0), App.Vector(0, 0, 1), d)) else: ProfileLib.RegularPolygon.makeRegularPolygon( 'SketchBase', 6, App.Vector(0.000000, 0.000000, -float(self.base_height)), App.Vector(self.shaft_diameter / 2, 0, 0), False) Gui.activeView().setActiveObject('pdbody', App.activeDocument().Gear) App.activeDocument().Gear.newObject("PartDesign::Pad", "PadBase") App.activeDocument().PadBase.Profile = App.activeDocument( ).SketchBase App.activeDocument().PadBase.Profile = doc.SketchBase App.activeDocument().PadBase.Length = float(self.base_height) App.activeDocument().recompute() Gui.activeDocument().hide("SketchBase") Gui.activeDocument().resetEdit() # Add Top to the Gear if self.addTop: Gui.activeView().setActiveObject('pdbody', App.activeDocument().Gear) App.activeDocument().Gear.newObject('Sketcher::SketchObject', 'SketchTop') #App.activeDocument().SketchTop.Support = (App.activeDocument().XY_Plane, ['']) App.activeDocument().SketchTop.MapMode = 'FlatFace' App.activeDocument().SketchTop.Placement = App.Placement( App.Vector(0.000000, 0.000000, float(self.hgear)), App.Rotation(0.000000, 0.000000, 0.000000, 1.000000)) App.activeDocument().recompute() doc.SketchTop.addGeometry( Part.Circle(App.Vector(0, 0, 0), App.Vector(0, 0, 1), self.top_diameter)) if self.shaft: if self.isCircle: if self.addKey: c = self.create_key(d, 0) keyLst = [] keyLst.append(Part.LineSegment(c[0], c[1])) keyLst.append(Part.LineSegment(c[1], c[2])) keyLst.append(Part.LineSegment(c[2], c[3])) doc.SketchTop.addGeometry(keyLst, False) doc.SketchTop.addGeometry( Part.ArcOfCircle(c[3], c[4], c[0])) else: doc.SketchTop.addGeometry( Part.Circle(App.Vector(0, 0, 0), App.Vector(0, 0, 1), d)) else: ProfileLib.RegularPolygon.makeRegularPolygon( 'SketchTop', 6, App.Vector(0.000000, 0.000000, 0), App.Vector(d, 0, 0), False) Gui.activeView().setActiveObject('pdbody', App.activeDocument().Gear) App.activeDocument().Gear.newObject("PartDesign::Pad", "PadTop") App.activeDocument().PadTop.Profile = App.activeDocument( ).SketchTop App.activeDocument().PadTop.Profile = doc.SketchTop App.activeDocument().PadTop.Length = float(self.top_height) App.activeDocument().recompute() Gui.activeDocument().hide("SketchTop") Gui.activeDocument().resetEdit() Gui.SendMsgToActiveView("ViewFit") progress_bar.stop()
def Activated(self): # Script to convert a mesh to a solid FreeCAD.Console.PrintMessage( 'Module to Convert to a refined Solid Started\n') FreeCAD.Console.PrintMessage(datetime.now().strftime('%H:%M:%S') + '\n') Start_time = datetime.now() #changeval = str(self.changevalue) sel = FreeCADGui.Selection.getSelection( ) # " sel " contains the items selected #Setup the Progress bar progress_bar = Base.ProgressIndicator() count = 0 for obj in sel: count = count + 1 progress_bar.start( "Converting " + str(count) + " Meshes to Refined Solids...", (count * 2)) #Calculate how many objects multiply by key steps of which 2 count = 0 for obj in sel: obj = sel[count] changeval = str(self.changevalue) if self.changevalue == "Solid_Mesh_Refined": #set doc to active document doc = App.activeDocument() FreeCAD.Console.PrintMessage(obj.Name + " Started Conversion to Solid\n") new_name = obj.Name + "_Solid_" + str( random.randrange(10**4, 10**5)) box = doc.addObject("Part::Feature", new_name) #Step 1 Create Part Shape box = Part.Shape() #Step 2 Convert Mesh to temporary part shape box.makeShapeFromMesh( FreeCAD.ActiveDocument.getObject(obj.Name).Mesh.Topology, 0.100000) # Step 3 #Step 3 move temporary shape to new object FreeCAD.ActiveDocument.getObject(new_name).Shape = box #Step 4 Purge the new solid FreeCAD.ActiveDocument.getObject(new_name).purgeTouched() progress_bar.next() #Step 5 Delete the temporary object del box FreeCAD.Console.PrintMessage( obj.Name + " Completed Conversion to Solid\n") #Step 6 refine mesh - App.ActiveDocument.addObject('Part::Feature','Mesh_Solid').Shape=App.ActiveDocument.Mesh_Solid.Shape.removeSplitter() refine mesh FreeCAD.Console.PrintMessage(obj.Name + " Started Refinement of Solid\n") doc.addObject('Part::Feature', "Refined_" + new_name).Shape = doc.getObject( new_name).Shape.removeSplitter() #Step 7 Remove intermediate Solid doc.removeObject(new_name) FreeCAD.ActiveDocument.recompute() #Step 8 Recompute document FreeCAD.Console.PrintMessage( obj.Name + " Completed Refinement of Solid\n") progress_bar.next() FreeCAD.Console.PrintMessage('Object Processed ' + str(count) + '\n') count = count + 1 Time_Taken = (datetime.now() - Start_time) progress_bar.stop Time_seconds = Time_Taken.total_seconds() FreeCAD.Console.PrintMessage( "Module to convert from Mesh to Refined Solid Completed Successfully in " + str(Time_seconds) + "Seconds\n")