How to export Fluent msh file from Mechanical via scripting?

Member, Moderator, Employee Posts: 242
50 Answers 100 Comments Second Anniversary 25 Likes
✭✭✭✭
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

Welcome!

It looks like you're new here. Sign in or register to get started.

Answers

  • Member, Moderator, Employee Posts: 242
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    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.
    1. 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.
    1. import os
    2. FilePath = r"D:\\FluentMeshFromWB.msh"
    3. system1 = GetSystem(Name="SYS")
    4. model1= system1.GetContainer(ComponentName="Model")
    5. model1.Edit(Hidden = True)
    6. model1.SendCommand(Command = '''DS = WB.AppletList.Applet('DSApplet').App;DS.Script.doFileExport("%s");'''%(FilePath))
    7. model1.Exit()
  • Member Posts: 11
    Name Dropper First Comment
    **
    edited January 2024

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

    1. mesh_15 = Model.Mesh
    2. mesh_15.GenerateMesh()
    3.  
    4. 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!

  • Member, Moderator, Employee Posts: 242
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭

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

    1. geomImportObj = DataModel.GetObjectsByType(DataModelObjectCategory.GeometryImport)[0]
    2. geomImportObj.Import(r"D:\test.scdoc")
  • Member Posts: 27
    10 Comments Name Dropper
    **
    edited June 2024

    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)?

  • Member, Employee, GitHub-issue-creator Posts: 353
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited July 2024

    @wanghao , Does this work on Linux?:

    1. FilePath = r"D:\FluentMeshFromWB.msh"
    2. JScmds = '''var DS = WB.AppletList.Applet('DSApplet').App;
    3. DS.Script.doFileExport("{}");'''.format(FilePath)
    4. ExtAPI.Application.ScriptByName("jscript").ExecuteCommand(JScmds)

Welcome!

It looks like you're new here. Sign in or register to get started.