Head-up Display projection system: from Speos to OpticStudio - part2

Authored By Julia Zhang, HunjuYi, Mike Grove and Alexandra Culler




To design a Head-Up Display (HUD) system in OpticStudio, it is convenient to begin by using Speos for the initial design setup. Speos allows for easy configuration of HUD projector elements, mirrors, eyebox, and virtual image. The CAD platform offers graphical interactivity and user-friendly operations, making it easier to apply constraints and volume constraints visually. This ensures a proper fit within the car from the beginning, allowing for the placement of optical elements embedded in car assemblies, such as the windshield and dashboard.

This article is one in a series of four that discusses the setup and optimization workflow for the HUD projection optical system, using Speos and OpticStudio.

This part covers the preparatory work needed to establish a connection between Speos and OpticStudio using the Python language. Both standalone and interactive connection modes are available for the connection. It provides boilerplate connection code and a necessary script code for converting Speos HUD design into OpticStudio's sequential mode.

Head-up Display projection system: from Speos to OpticStudio - part1

Prepare for Speos to OpticStudio conversion

We are using SpaceClaim, a CAD platform that integrates Speos. There are other CAD platforms that also integrate Speos. To automatically convert the HUD system from Speos to OpticStudio sequential mode, we will utilize the SpaceClaim script. SpaceClaim script is a tool integrated into the SpaceClaim CAD platform that allows for automation and customization. The script enables automated operations and coordinates the translation from Speos to OpticStudio. It uses IronPython as its scripting language so that it can be run on the .NET framework. The interpreter is built-in, and it allows for running the Python script code and testing things out.

In OpticStudio, we do not have a built-in interpreter. To use the Zemax OpticStudio API (ZOS-API) with Python, we need an integrated development environment (IDE) like PyCharm and the Python module Pythonnet. Pythonnet connects the .NET runtime and Python, enabling the execution of Python code with OpticStudio’s functionalities.

Navigate to the IronPython library folder located at C:\Program Files \ANSYS Inc\v241\ scdm\Library\IronPython\Lib. Copy and paste the attached two .py files named zosapi_interactive.py and zosapi_standalone.py into this folder. Refer to the 'Modes: Different ways of connection' section in this article for information about supported connection modes when using ZOS-API. The two provided .py files correspond to interactive connection and standalone connection, respectively.

The default folder to paste the .py file into is determined by the chosen API version. For instance, if you opt for API: V241, then the .py file should be in the v241 folder. For instructions on accessing the connection code when files are placed in other folders, please refer to the end of this section.


Figure 1.1: API version options

To utilize OpticStudio functionalities in SpaceClaim using Python, start by importing the module and running it with the SpaceClaim Python interpreter. The code lines below demonstrate how to open a new lens file and save it as SPESO1.zos.


Figure 1.2: Use Standalone Connection in Speos

When the console displays a message like” No module named zosapi_interactive/ zosapi_standalone” while running the code, it means that the module cannot be found in the system path.


Figure 1.3: No module error

To resolve this, you need to determine the location of the current code system path and place the mentioned connection .py code within that path. Use the code line below to print the current system paths.

import sys
for path in sys.path:

For example, if the two downloaded .py files are in the folder C:\Users\julzhang\Downloads and you want the SpaceClaim Python script to access these .py files from this folder, you can include the path into the system path in Python:

import sys 

Notes on installing Python modules: IronPython supports a subset of the Python Standard Library. However, due to differences between the .NET platform and the Python C API, not all modules are fully functional. Notably, commonly used modules like Numpy and Scipy are not supported. It is recommended to use the .NET library instead. For instance, MathNet.Numerics.dll is a component of the MathNet.Numerics library, a .NET library de-signed for numerical computing.

The reference DLL already exists in the api folder. For example, to add this reference, use the following line of code:

import clr
clr.AddReferenceToFileAndPath(r C:\Program Files\ANSYS Inc\v241\Discovery\MathNet.Numerics.dll )

Running Speos script for OpticStudio sequential mode conversion

Before running the Python script, ensure the HOD analysis is up-to-date by checking the Design tab. Right-click and select “Compute” if not. Confirm the HOD name to verify the correct design is to be converted. Ensure the .txt output report is ready, as the conversion will use data from this output text file.


Figure 2.4: Speos Design tab

The methods used across specific versions should be consistent. Users might use a customized HUD Optical Design name. However, the HOD must be defined under the root component, not a subcomponent, as the script only accepts this configuration. The script will prompt users to select an HOD design interactively from the Design tab. This allows the script to read and use the settings associated with the chosen HOD design. The attached .scscript file utilizes OpticStudio’s interactive connection mode, enabling visual monitoring of the conversion process through the open OpticStudio user interface.

To run the script, first open the OpticStudio interface and select Programming > Interactive Connection to initiate a connection with Speos. Then, in Speos, navigate to Design > Record > Script to open the downloaded script file and click on” Run Script”.


Figure 2.5: OpticStudio interactive connection


Figure 2.6: Run Speos script


Figure 2.7: Select HOD from Design tab


Figure 2.8: Converted OpticStudio sequential file

Was this article helpful?
0 out of 0 found this helpful



Please sign in to leave a comment.