How to export Fluent msh file from Mechanical via scripting?
How to export Fluent msh file from Mechanical via Scripting? One can export it via GUI in Mechanical --> File --> Export
Answers
-
There are two methods to export the .msh file.
- Interal Object method (works only for Windows): Run the below script either in Mechanical Scripting Console or Python Code object.
ExtAPI.DataModel.Project.Model.Mesh.InternalObject.WriteFluentInputFile(r"D:\FluentMesh.msh")
- Jscript method: Exporting from WB via WB scripting. Paste the below script in WB --> Scripting --> Command window. This script exports .msh file from "Model" component.
import os FilePath = r"D:\\FluentMeshFromWB.msh" system1 = GetSystem(Name="SYS") model1= system1.GetContainer(ComponentName="Model") model1.Edit(Hidden = True) model1.SendCommand(Command = '''DS = WB.AppletList.Applet('DSApplet').App;DS.Script.doFileExport("%s");'''%(FilePath)) model1.Exit()
2 -
@Rohith Patchigolla Hi, i am using above code to export .msh format file
for i in range(100):
ExtAPI.Application.ImportGeometry('E:\DC_geometry\len_geometry\save{j}.scdoc'.format(j=i+1))mesh_15 = Model.Mesh mesh_15.GenerateMesh() ExtAPI.DataModel.Project.Model.Mesh.InternalObject.WriteFluentInputFile(r"E:\\DC_geometry\\3_meshed_geometry\\sav{j}.msh".format(j=i+1))
there is problem in above code is that imports only one geometry like save1 and then mesh that geometry and saves that same meshed geometry multiple times just changing name like sav1,sav2...so on. Real problem is that imports only one geometry and then showing warning that geometry already exists so another geometry can't be import, i have to delete that meshed geometry and then import another geometry to mesh.
In short can you provide me code of deleting the meshed geometry so i can import another geometry for meshing.
please help me!1 -
Hello @ramsaran , you could the below script to replace the geometry.
geomImportObj = DataModel.GetObjectsByType(DataModelObjectCategory.GeometryImport)[0] geomImportObj.Import(r"D:\test.scdoc")
1 -
Hi @Rohith Patchigolla
Is there any way to do it on linux?
Or how the second method (jscript method) can be run it on linux in mechanical scripts(ACT)?0 -
@wanghao , Does this work on Linux?:
FilePath = r"D:\FluentMeshFromWB.msh" JScmds = '''var DS = WB.AppletList.Applet('DSApplet').App; DS.Script.doFileExport("{}");'''.format(FilePath) ExtAPI.Application.ScriptByName("jscript").ExecuteCommand(JScmds)
1