How to export Fluent msh file from Mechanical via scripting?

Rohith Patchigolla
Rohith Patchigolla Member, Moderator, Employee Posts: 86
First Answer First Anniversary Name Dropper Solution Developer Community of Practice Member
edited November 2023 in Structures

How to export Fluent msh file from Mechanical via Scripting? One can export it via GUI in Mechanical --> File --> Export

Answers

  • Rohith Patchigolla
    Rohith Patchigolla Member, Moderator, Employee Posts: 86
    First Answer First Anniversary Name Dropper Solution Developer Community of Practice Member
    edited November 2023

    There are two methods to export the .msh file.

    1. 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")
    
    1. 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()
    
  • ramsaran
    ramsaran Member Posts: 4
    Name Dropper First Comment
    edited January 9

    @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!

  • Rohith Patchigolla
    Rohith Patchigolla Member, Moderator, Employee Posts: 86
    First Answer First Anniversary Name Dropper Solution Developer Community of Practice Member

    Hello @ramsaran , you could the below script to replace the geometry.

    geomImportObj = DataModel.GetObjectsByType(DataModelObjectCategory.GeometryImport)[0]
    geomImportObj.Import(r"D:\test.scdoc")