March 29, 2022
Nowadays you don’t have to be a computer programmer to find your way around code. Many built-in tools provide user-friendly assistance to guide you, whether you are a beginner or an expert, democratizing technology, simulation, and computer-aided engineering (CAE). For OpticStudio, this type of easy-to-use tool is the Zemax OpticStudio application programming interface (ZOS-API).
With ZOS-API, you can significantly boost the capabilities of OpticStudio and ultimately, your simulations. ZOS-API not only allows you to access everything in OpticStudio, but it also allows you to customize the software for your specific designs. Further, it makes it easy to embed OpticStudio data into your simulations to solve greater challenges, create more possibilities, and enhance your optical design projects.
To get the most value from ZOS-API and be able to examine and implement its code more easily, it is beneficial for designers to have a deeper understanding of this built-in interface.
As its inner workings operate similarly to OOP, let’s start there.
As mentioned above, within OOP languages the data is categorized into objects, which are part of classes. This makes the code easily accessible for use in future projects. This form of code inheritance saves significantly on time. An example of this concept can be seen in an OpticStudio file.
Each Zemax (.zmx) file represents a unique optical system, which can be presented in sequential and/or non-sequential mode — each with an individual number of objects or surfaces — though optical systems may share common characteristics, such as wavelengths or surfaces.
In OOP, these optical systems are classified as API objects, while common characteristics are grouped into a master list referred to as an API class or an interface.
These API classes are then grouped into libraries referred to as namespaces.
This structured, or grouped, modularity of OOP language simplifies any troubleshooting, data correction, or data revision as you can navigate directly to the point in question, without having to sort through entire pages of code.
Now that you are better versed in OOP, you can think of ZOS-API as a namespace (shown in Figure 3), or higher rank of interfaces, that determines which attributes, or characteristics, are available for the object.
Therefore, when you engage ZOS-API, you are ultimately constructing API objects with attributes.
These attributes are properties or functions available to you. A property allows you to define or read a stored value, or setting, while a function serves as a command, or action, that you can assign to your object.
For example, if we look at the class INSCRayTrace, which is the non-sequential raytracing class, a property can be used to define its settings, such as ignoring errors, as shown in Figure 4. A function can be used to clear detectors before running the raytrace, as shown in Figure 5.
Essentially, ZOS-API’s property and function capabilities allow you to perform the same operations at this stage that you can in the interface stage — highlighting one of the structure’s main advantages — that everything can be automated and post-processed.
Selecting a function or property for an object returns results ranging from numbers to text strings or a Boolean true or false response, for example: int value = Object1.NumberOfFields.
Another possible result may be a new object, for example: IField New_Object = Object1.GetField(1).
Some properties require you to either get or set a value, as follows:
You can take a closer look at your code structure by applying sample code via the ZOS-API help function under the programming tab in the OpticStudio task bar, as pictured in Figure 6.
First, open the following sample file in OpticStudio:
\Zemax\ZOS-API Sample Code\C#\CSharpStandalone_01_new_file_and_quickfocus.cs
Though the sample code is written in C# programming language, you can easily open it with a text editor, regardless of the programming language you are using.
Next, open the ZOS-API Syntax Help option, also shown in Figure 6.
The main interface is identified as IOpticalSystem, as seen in Figure 7, and is equivalent to a single .zmx file.
Here you can easily access data for the interface, including functions and properties, by selecting ZOSAPI.IOpticalSystem as shown in Figure 8.
With its ease-of-use, accessibility, and capabilities, ZOS-API enables you to optimize OpticStudio and provides direct access to the data and coding you need to enhance your simulations and optical design projects.
To learn more about the ZOS-API structure, browse a free tutorial on the Zemax website that includes information, articles, and training resources.
To explore OpticStudio, register for a free trial today.