Skip to main content

Introduction

Very often, when working on a simulation project, many Workbench project variants are created, creating a group of Workbench projects in a directory, for which it is often desired to archive them for posterity and safe keeping.  However, if the projects are not archived after completion while open in session, it becomes a repetitive task to open each (of possibly many) project and archive it.  Fortunately, the task of archiving all or a subset of the projects in a directory is easily automated using PyWorkbench, part of the PyAnsys ecosystem.

At the time of this writing, we will be using Python 3.12 with the latest version of PyAnsys at the time of the 2025 R2 release.  Note that Python 3.12 and PyAnsys need to be installed (see PyAnsys installation instructions), preferably in a virtual environment, and that this script should work with older versions of Ansys, i.e., 2024 R1, 2024 R2 and 2025 R1, but some validation may be required.

Example Scenario

In this example, we have three Workbench 2025 R2 projects in a working directory: model_1.wbpj, model_2.wbpj, and model_3.wbpj.  Our goal is to archive all three projects with results except for model_2 which will be archived without results.

Python Script

In order to automate the process, we will place the python script into the directory that contains the Workbench projects and run it from there.

Module Imports

The following modules are required for this script:

Get List of all Workbench Projects in the Directory

The first task at hand is to generate a list of the Workbench projects to be archived.  Here, we us the Python glob module to retrieve all of them and place them in a list.  Alternatively, one could manually generate the list.

Create an Archives Dictionary to Specify Parameters for Each Archive

Next, we create a dictionary that, for each project, will describe whether to include results files and corresponding archive project name.  For archives with results, we use the same name as the project.  For archives without results, we append said project names with "_no_results" in order to readily distinguish them.

PyWorkbench Control String

To interact with Workbench using PyWorkbench, a IronPython string is needed to control Workbench.  The control string allows for string interpolation in much the same way as standard Python formatted strings.  Thus, we programmatically substitute the Workbench project name into the `project_name` variable in order to direct Workbench into opening the desired Workbench project.

Launch Workbench, Archive Each Project, and Close Workbench

Now that all of the prework is complete, we run the main portion of the script.  Firstly, we launch Workbench 2025 R2 without the GUI for speed purposes.  Secondly, we loop through the Workbench project list and archive them according to the settings in the `archives` dictionary.  Finally, we close Workbench gracefully. 

End Result

After running the script, we see that the project archives have been successfully created.

Conclusion

Automating repetitive tasks using PyAnsys is very straightforward.  Very often we can save much time and effort in future projects by investing the time to generate PyAnsys scripts.

Downloadable Content

Python 3.12 script

Ozen Engineering Expertise

Ozen Engineering Inc. leverages its extensive consulting expertise in CFD, FEA, optics, photonics, and electromagnetic simulations to achieve exceptional results across various engineering projects, addressing complex challenges such as antenna design, signal integrity, electromagnetic interference (EMI), and electric motor analysis using Ansys software.

We offer support, mentoring, and consulting services to enhance the performance and reliability of your electronics systems. Trust our proven track record to accelerate projects, optimize performance, and deliver high-quality, cost-effective results. For more information, please visit https://ozeninc.com.

If you want to learn more about our consulting services, please visit: https://www.ozeninc.com/consulting/

CFD: https://www.ozeninc.com/consulting/cfd-consulting/ 

FEA: https://www.ozeninc.com/consulting/fea-consulting/ 

Optics: https://www.ozeninc.com/consulting/optics-photonics/ 

Photonics: https://www.ozeninc.com/consulting/optics-photonics/ 

Electromagnetic Simulations: https://www.ozeninc.com/consulting/electromagnetic-consulting/ 

Thermal Analysis & Electronics Cooling: https://www.ozeninc.com/consulting/thermal-engineering-electronics-cooling/

Mark Lytell
Post by Mark Lytell
Aug 20, 2025 2:01:57 PM