How can I export results summary worksheet in Mechanical?

Tom David
Member, Employee Posts: 6
✭✭✭


How can I export the result summary worksheet to a text file through python ACT?
Tagged:
0
Answers
-
To my knowledge, access to worksheet is not yet exposed in ACT scripting. A possible workaround is to use jscript. The below code uses unsupported and undocumented commands, use at your own risk:
- analysis = ExtAPI.DataModel.Project.Model.Analyses[0] # First analysis
- analysis.Solution.Activate() #Activating solution
- ExtAPI.Application.ScriptByName("jscript").ExecuteCommand('WB.PreferenceMgr.Preference("PID_Open_Excel") = 0;') # Blocking Excel from opening after export
- ExtAPI.Application.ScriptByName("jscript").ExecuteCommand('DS.Script.toggleWorksheetVisibilityInContexMenu();') # Turn on worksheet mode with "Result Summary" section selected
- ExtAPI.Application.ScriptByName("jscript").ExecuteCommand('DS.Script.doExportWorksheetToTextFile("D:/WorsheetResult.txt");') # Exporting result, replace path in this line
0 -
If you want to execute this functionality from WB-project page, the way would be the following:
- my_system=GetSystem(Name="SYS")
- my_model = my_system.GetContainer(ComponentName="Model")
- my_model.Edit(Hidden=True)
- cmd="""analysis = ExtAPI.DataModel.Project.Model.Analyses[0]
- analysis.Solution.Activate()"""
- my_model.SendCommand(Language="Python",Command=cmd)
- cmd2="""DS = WB.AppletList.Applet("DSApplet").App;
- WB.PreferenceMgr.Preference("PID_Open_Excel") = 0;
- DS.Script.toggleWorksheetVisibilityInContexMenu();"""
- my_model.SendCommand(Language="Javascript", Command=cmd2)
- cmd3="""DS = WB.AppletList.Applet("DSApplet").App;
- var MyWait = DS.Script.AnsObjectFactory.CreateDispatchObject("WBControls.WBTestHelper.211");
- MyWait.Wait(2000);
- DS.Script.doExportWorksheetToTextFile("D:////WorsheetResult.txt");"""
- my_model.SendCommand(Language="Javascript", Command=cmd3)
- my_model.Exit()
0