Also available in 日本語
Authored By Julia Zhang, Hunju Yi, Mike Grove and Alexandra Culler
Introduction
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.
Save the two attached Python files, zosapi_interactive.py and zosapi_standalone.py, in a folder accessible from the Speos(SpaceClaim) scripting environment. The files correspond to the interactive and standalone ZOS-API connection modes, respectively. Refer to the “Modes: Different ways of connection” section in Sample code for ZOS-API users for more information about the supported connection modes.
The connection files do not need to be copied into the IronPython library folder. Instead, specify their folder location at the beginning of the Speos(SpaceClaim) script converter_interactive_GUI.scscript. Open the file in Speos and modify the location. For example, if the two downloaded .py files are in the folder D:\HUD_Speos_to_OpticStudio_converter :
Figure 1.1: .py file location
import sys
# Set the folder path containing zosapi_interactive.py and zosapi_standalone.py.
sys.path.append(r'D:\HUD_Speos_to_OpticStudio_converter')
If you are using a Speos version other than 26R1, please update the API version in the Script Editor using the API version drop-down menu to match your Speos (SpaceClaim) version. In addition, update the API version identifier in the provided script converter_interactive_GUI.scscript by modifying the V261 portion of the following import statement to the same version:
Figure 1.2: 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.3: Use Standalone Connection in Speos
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.
![Design_tab[1].png](https://downloads.zemax.com/Zemax-portal/knowledge_articles/28011245983763/Images/Picture4en-us.png)
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”.
![Interactive_connection[1].png](https://downloads.zemax.com/Zemax-portal/knowledge_articles/28011245983763/Images/Picture5en-us.png)
Figure 2.5: OpticStudio interactive connection
Figure 2.6: Run Speos script

Figure 2.7: Select HOD from Design tab
![Converted_result[1].png](https://downloads.zemax.com/Zemax-portal/knowledge_articles/28011245983763/Images/Picture8en-us.png)
Figure 2.8: Converted OpticStudio sequential file