This article introduces Ansys optical automation library to get a basic understanding and guidance on how to download and use it. Different IDE (Integrated Development Environment) can be used to work with Ansys optical-automation. In this article we will show how to use it with IDLE (installed by default with Python). If you want to use Visual Studio or PyCharm as IDE to run the Ansys optical-automation project you can refer to this article Ansys open project on GitHub | Zemax Community.
The Optical Automation library gathers functionalities and tools for Ansys Speos, Zemax, and Lumerical automations and interoperations. For Speos, this library allows you to create workflows combining different preprocessing and postprocessing modules.
Structure of the GitHub repository
The GitHub repository of the Ansys optical-automation library is public and can be accessed optical-automation/ansys_optical_automation at main · ansys/optical-automation · GitHub.
Under the application folder you can find a number of final script examples that are ready to use.
These examples are using the classes which are defined below in the _core and _process folders.
Please be aware that scripts run from the Speos interface use IronPython, whereas scripts run from IDLE or other editor use CPython, the reference implementation of the Python programming language.
Your contributions to this library are welcome and encouraged. To learn how to contribute, see the Contribute document.
Ansys is committed to delivering our customers with the best automation workflow solutions. Should you require assistance in developing a customized workflow for your project, please do not hesitate to reach out to your local support. If you encounter any bugs within the solution, kindly contact us and our team will promptly address and rectify the issue.
The Optical Automation library is licensed under the MIT license.
Step by step
Users can go to https://www.python.org/downloads/ to download and install Python. We suggest using the latest version or at least “Python 3.9”. Click the Download or choose a specific version to download the installation package.
During the installation, make sure to check the option to “Add python.exe to Path”.
After completing the installation, you can validate the installation by opening a prompt window and typing “python” + Enter. If you see an interface like below, your Python has been successfully installed!
Download Ansys optical-automation repository
Go to GitHub - ansys/optical-automation: Optical Automation Framework, click on Code and choose “Download ZIP”
Unzip the downloaded folder to your local machine.
Note: This is basically a manual “cloning” of the repository. The repository can be cloned properly using git commands. The cloning of the repository is not detailed here for the sake of simplicity. If you are interested to the solutions which are still developed at a different branch, you click the main and switch to the branch to download
Configure optical-automation by installing necessary Python libraries
Some of the scripts inside the Ansys optical-automation require Python libraries like numpy or scipy to enable scientific calculations. In Ansys optical-automation, those required libraries have been defined in the pyproject.toml file.
To install all the necessary libraries, open a prompt window and type pip install -e "path of the optical automation folder" and press Enter.
Now, you are all settled to use Ansys optical-automation!
Example of run rayfile converter
The code from optical-automation library can be run using IDLE installed by default with Python.
The next steps of how to run an example will be shown on the “rayfile converter example”, that contains a script to convert a rayfile from Speos to Zemax or from Zemax to Speos. The rayfile_converter_example.py can be found in Ansys_optical_automation > Application.
- Open IDLE Window
- Click on File -> Open -> Select the python file “rayfile_converter_example.py” from the application folder in your downloaded Ansys optical automation library
- Append the path to the locally downloaded/cloned repository in the code like shown below:
- With “Run Module” (F5) you can run the conversion tool.
- A window will prompt for selecting the file you want to convert. Users can select .ray, .sdf and .dat in this window for conversion. Example ray files can be found under optical-automation\tests\workflows\example_models
- The converted file will be generated in the same folder as the file we select.
Related KB pages: