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

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
-
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).
0
Answers
-
Thank you Mike, this solves my problem.
I will use
solution.ReadGivenAnsysResultFileByReference(rst_file_path, Ansys.Mechanical.DataModel.Enums.UnitSystemIDType.UnitsNMM) # reference of .rst to working directory
or
solution.ReadGivenAnsysResultFile(rst_file_path, Ansys.Mechanical.DataModel.Enums.UnitSystemIDType.UnitsNMM) # copy .rst to working directorysee also another post:
https://discuss.ansys.com/discussion/147/using-act-how-can-i-read-a-result-file-in-mechanical-similarly-to-tools-read-result-file-and-sp0