PyMechanical - How to open an existing Mechanical file with solution to get data out of it?

Daniel169
Daniel169 Member Posts: 4
First Comment
**

Hello,

there is a static structural system that has already been created and solved via a manual Workbench process.

With PyMechanical scripting, I want to open it remotely in an automated way to retrieve several pieces of data from different locations in the tree (e.g. named selections, contacts, geometry) and also result information (e.g. node deformations from all named selections). For this, I want to use mechanical scripts with the mechanical.run_python_script() method.

I can open the .mechdb file via ExtAPI.DataModel.Project.Open(). How can I set the working (result) folder to the existing dp0\SYS-7\MECH folder so that I can access the results with the mechanical scripts, as it is when you open the system from Workbench manually? It currently shows me the result folder dp0\global\MECH\SYS-7_Mech_Files\StaticStructural as the working folder.

Best Answer

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 404
    100 Likes 25 Answers 100 Comments Second Anniversary
    ✭✭✭✭
    Answer ✓

    I think the more stable way to do this would be to let the working directory be default, and then use the API to read results file. I don't know the APIs off hand, but open mechanical, activate a solution object, and see the menu button to read results file. This will open a file search UI, and you can pick an .rst file. Record this action the script console of Mechanical to get the APIs.

    This solves the problem from a backwards standpoint, of working directory is same, but the results file can still be referenced (does not need to be in that directory, or can be copied to it).

Answers