How can I export results summary worksheet in Mechanical?

Options
Tom David
Tom David Member, Employee Posts: 6
First Anniversary Ansys Employee First Comment Solution Developer Community of Practice Member
edited December 2023 in Structures

How can I export the result summary worksheet to a text file through python ACT?

Tagged:

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 827
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    edited December 2023 Answer ✓
    Options

    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
    
  • Javier Vique
    Javier Vique Member, Employee Posts: 78
    First Answer First Anniversary Name Dropper 5 Likes
    Answer ✓
    Options

    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()