Solve Workbench archive without open it

Member Posts: 34
10 Comments 5 Likes First Anniversary Name Dropper
**

Hi,
I have multiple Workbench archive, and I would like to run them all, in order to extract some results.
But, I don't want to do it mannualy (open all the archives, and solve them all).
Is there a way in python for running a Workbench archive and solve the system in it?

Something like this :

  1. # Parameters
  2. folder_path = xxx
  3.  
  4. # List of archives
  5. import os
  6. archives = []
  7. for file in os.listdir(folder_path ):
  8. if file.endswith(".wbpz"):
  9. archives.append(os.path.join(folder_path , file))
  10.  
  11. # Run
  12. for archive in archives:
  13. # archive solve

Regards,
Jean

Answers

  • Member, Employee Posts: 392
    100 Likes 25 Answers 100 Comments Second Anniversary
    ✭✭✭✭
    edited April 8

    You will need to open a WB session in batch via the .exe file path. You can then use the command line args to have WB run a script file. Some example code to run WB in batch via iron python is below. Dynamically create the project-specific python script file for this WB session to run. It should only be a few lines like: Open project -> Update Project. They only dynamic part is the file path, which you should already have.

    You can also record the APIs in WB via File>Scripting>Record Journal. Click the "Update Project" button in the UI to get the proper API call to update the entire project from the schematic page.

    Alternatively, you can pip install PyWorkbench and use your python environment directly. Open WB via PyWorkbench, open the project archives with WB api calls, then do the "Update Project" API for each one. You can close WB application after each, but you could also leave it open and just close/open next project on the list.

    1. def RunAnsWorkbench(Interactive=True, ScriptFile=None, WaitForProcess=False):
    2. """
    3. Run the analysis with a new session of workbench that is started as a new process
    4. """
    5. SI = System.Diagnostics.ProcessStartInfo()
    6. SI.FileName = WbExePath
    7. if Interactive:
    8. SI.Arguments = "-I"
    9. else:
    10. SI.Arguments = "-B"
    11. if ScriptFile!=None:
    12. SI.Arguments += " -R "+"\""+ScriptFile+"\""
    13. Process = System.Diagnostics.Process.Start(SI)
    14. if WaitForProcess:
    15. System.Diagnostics.Process.WaitForExit(Process)
    16. return SI

Welcome!

It looks like you're new here. Sign in or register to get started.