How to call a script (python) in Mechanical APDL


Good morning,

I am currently working on an APDL script where I export some data in .mat format. To manipulate this data further, I am using a Python script. However, I'm encountering difficulties calling my Python script within my APDL script.

The call to my Python script is within the /post1 section of my APDL script. It appears that my command is not being recognized by the system. I have attempted several methods to execute the Python script without success.

Here are the methods I've tried:

Using *CFOPEN command:

*CFOPEN pythonpath, D:\user\files\user_files\

Directly calling a batch file:

/SYS 'D:\user\files\user_files\launchMyPython.bat'

Embedding Python script within APDL:

*CFOPEN, call_python, inp
*VLEN, 1
*VWRITE, 'D:\user\files\user_files\launchMyPython.bat'
/SYS, %c

However, I keep receiving the following error message: "D:\user\files\user_files\launchMyPython.bat is not recognized as an internal command or external, an executable program or a command file."
Ps: the calling is working directly from the terminal

Could you please advise on what I might be doing wrong? Any documentation or advice on this matter would be greatly appreciated.

Thank you very much for your assistance.

Best regards,



  • Chris Harrold
    Chris Harrold Member, Administrator, Employee Posts: 117
    First Answer First Comment First Anniversary Ansys Employee

    @AKD-Scripting-Team - anyone have any thoughts on this?

  • M
    M Member, Employee Posts: 230
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member

    @AlexandreCa51 Are you running this from a Mechanical command (apdl) snippet or directly in APDL (Ansys Classic)?

  • Rohith Patchigolla
    Rohith Patchigolla Member, Moderator, Employee Posts: 115
    First Answer First Anniversary Name Dropper Solution Developer Community of Practice Member
    edited April 18

    Hello @AlexandreCa51 ,

    could you please try below, (/sys, pythonpath pythonfile)?

    /SYS,C:\Users\xxxxxx\AppData\Local\Programs\Python\Python38\python.exe D:\