Solve Workbench archive without open it

Jean
Jean 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 :

# Parameters
folder_path = xxx

# List of archives
import os
archives = []
for file in os.listdir(folder_path ):
    if file.endswith(".wbpz"):
        archives.append(os.path.join(folder_path , file))

# Run 
for archive in archives:
     # archive solve

Regards,
Jean

Answers

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 391
    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.

    def RunAnsWorkbench(Interactive=True, ScriptFile=None, WaitForProcess=False):
        """
        Run the analysis with a new session of workbench that is started as a new process
        """
        SI = System.Diagnostics.ProcessStartInfo()
        SI.FileName = WbExePath
        if Interactive:
            SI.Arguments = "-I"
        else:
            SI.Arguments = "-B"
        if ScriptFile!=None:
                SI.Arguments += " -R "+"\""+ScriptFile+"\""
        Process = System.Diagnostics.Process.Start(SI)
        if WaitForProcess:
            System.Diagnostics.Process.WaitForExit(Process)
        return SI