def Activated(self): filters = u"IDES mesh (*.unv);;Med mesh(*.med);;VTK mesh (*.vtk *.vtu)" mesh_file = QFileDialog.getOpenFileName(None, u"Open mesh files", u"./", filters) mesh_file = mesh_file[0] # why return a tuple of filename and selectedfilter import CfdTools if not CfdTools.getActiveAnalysis(): CfdTools.createAnalysis() FreeCADGui.addModule("CfdTools") sel = FreeCADGui.Selection.getSelection() if (len(sel) == 1) and (sel[0].isDerivedFrom("Part::Feature")): # using existing part_feature, no need to import geometry, but get obj as link geo_obj = sel[0] CfdTools.importGeometryAndMesh( geo_obj, mesh_file) #Todo: macro recording is yet support else: filters = u"BREP (*.brep *.brp);;STEP (*.step *.stp);;IGES (*.iges *.igs);; FcStd (*.fcstd)" geo_file = QFileDialog.getOpenFileName(None, u"Open geometry files", u"./", filters) geo_file = geo_file[0] FreeCADGui.doCommand( "CfdTools.importGeometryAndMesh(u'{}', u'{}')".format( geo_file, mesh_file)) FreeCADGui.Selection.clearSelection() FreeCADGui.addModule("FemGui") #if FemGui.getActiveAnalysis(): # besides addModule, FemGui need to be imported FreeCADGui.doCommand( "FemGui.getActiveAnalysis().addObject(App.ActiveDocument.ActiveObject)" )
def select_without_widget(self): filters = u"IDES mesh (*.unv);;Med mesh(*.med);;VTK mesh (*.vtk *.vtu)" #;;GMSH mesh (*.msh) not supported, converted to unv or vtk mesh_file = QFileDialog.getOpenFileName(None, u"Open mesh files", u"./", filters) mesh_file = mesh_file[0] # why return a tuple of filename and selected filter sel = FreeCADGui.Selection.getSelection() if (len(sel) == 1) and (sel[0].isDerivedFrom("Part::Feature")): # using existing part_feature, no need to import geometry, but get obj as link geo_obj = sel[0] CfdTools.importGeometryAndMesh(geo_obj, mesh_file) # Todo: macro recording is yet support, get geo_obj else: filters = u"BREP (*.brep *.brp);;STEP (*.step *.stp);;IGES (*.iges *.igs);; FcStd (*.fcstd)" geo_file = QFileDialog.getOpenFileName(None, u"Open geometry files", u"./", filters) geo_file = geo_file[ 0] # can be None? link mesh_obj.Part later manually by user FreeCADGui.doCommand( "CfdTools.importGeometryAndMesh(u'{}', u'{}')".format( geo_file, mesh_file))