How to export mesh as .msh file from Mechanical using PyMechanical

kwheeler9
kwheeler9 Member Posts: 1 **

Hi all,

I'm trying to export a mesh file in .msh format from a session of Mechanical 2024 R2 using PyMechanical. I've found this post, and tried to implement the solution:

https://discuss.ansys.com/discussion/2715/how-to-export-fluent-msh-file-from-mechanical-via-scripting

But when I try to use the line:
ExtAPI.DataModel.Project.Model.Mesh.InternalObject.WriteFluentInputFile(r"D:\FluentMesh.msh")

I get the following error:

'__ComObject' object has no attribute 'WriteFluentInputFile'

And if I try dir(ExtAPI.DataModel.Project.Model.Mesh.InternalObject), I can in fact see there is no attribute 'WriteFluentInputFile'.

dir(ExtAPI.DataModel.Project.Model.Mesh.InternalObject)

['CreateObjRef', 'Equals', 'Finalize', 'GetHashCode', 'GetLifetimeService', 'GetType', 'InitializeLifetimeService', 'MemberwiseClone', 'Overloads', 'ReferenceEquals', 'ToString', 'class', 'delattr', 'dir', 'doc', 'eq', 'format', 'ge', 'getattribute', 'gt', 'hash', 'init', 'init_subclass', 'le', 'lt', 'module', 'ne', 'new', 'overloads', 'reduce', 'reduce_ex', 'repr', 'setattr', 'sizeof', 'str', 'subclasshook']

Does anyone know why this is happening and what the correct way to export the mesh would be?

Thanks!
Kyle

Comments

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee, GitHub-issue-creator Posts: 331
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited January 14

    Did you try using the jscript method?:

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

    If that doesn't work, can you post more details? (e.g. Are you running remote or embedded PyMechanical? What version of PyMechanical?)