Hi Everyone,
I want to automatically run hundreds of transient thermal simulation and export the result data, what I have done until now includes:
1) successfully wrote an IronPython script that could command the ANSYS Mechanical to run the simulations in turn and export the data files. This script was written in Mechanical-Automation-Scripting, which means the script was run in the Mechanical environment.
2) finished a Matlab script which could start the ANSYS Workbench (by RunWB2.exe) and call the IronPython script.
The this is: I did not wrote all the settings in the IronPython script, some of settings were done manually in a workbench project file (.wbpj), which means I need to open the .wbpj and then run the simulations in this project file. In conclusion, my plan is:
1) run Matlab script
2) open the Workbench exe (in Matlab script)
3) call the IronPython script (in Matlab script)
4) open the existing .wbpj file (in IronPython script)
5) run the simulations as script command (in IronPython script)
Now I am stuck in the step 4, where I cannot open the existing .wbpj.
My Matlab script is:
ansysPath='D:\Program Files\ANSYS Inc\v202\Framework\bin\Win64\RunWB2.exe';
system(['start "" "',ansysPath,'"']);
pause(15);
ironpython_path='D:\Program Files\ANSYS Inc\v202\commonfiles\IronPython\ipy.exe';
pythonScriptPath='my_path\ScriptingTest1.py';
setenv('IRONPYTHONPATH', 'D:\Program Files\ANSYS Inc\v202\aisol\bin\winx64');
command=sprintf('"%s" "%s"',ironpython_path,pythonScriptPath);
status=system(command);
The beginning of my IronPython script is:
import os
import sys
import clr
from System import Array
app = MechanicalApp()
project = app.OpenProject(r"my_path\simu1.wbpj")
model = ExtAPI.DataModel.Project.Model
TRANSIENT_THERMAL = DataModel.AnalysisByName("Transient Thermal")
Now after running the Matlab script, a brand new workbench was opened but the script is terminated and return a error message "NameError: global name 'MechanicalApp' is not defined". Is there any method that can open the existing .wbpj by IronPython script?
Thanks for all suggestions and helps!