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\lauchMyPython.py

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
*CFCLOS

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,
Alexandre

Tagged:

Answers

  • Chris Harrold
    Chris Harrold Member, Administrator, Employee Posts: 183
    5 Answers 100 Comments Photogenic Name Dropper
    admin

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

  • M
    M Member, Employee Posts: 235
    100 Comments Photogenic 5 Likes Name Dropper
    ✭✭✭✭

    @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: 175
    100 Comments Photogenic Ansys Employee 5 Likes
    ✭✭✭✭
    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:\lauchMyPython.py