The differences between ZOS-API, ZPL and DLL

This article will walk through a comparison of ZOS-API, ZPL and DLLs. We will explain the interaction with OpticStudio, code execution, syntax, and data access and processing.

Authored By Haosheng Hu



In OpticStudio, the Programming Tab provides user access to OpticStudio's programming features, such as the Zemax Programming Language (ZPL), Application Programming Interface (ZOS-API) and Dynamic Link Library (DLL). Each method of programming has its own unique specialty. This article describes the characteristics and differences of each of the three programming features.

Differences between ZOS-API and ZPL

ZOS-API and ZPL differ in many ways, including their syntax, applications, and runtime environments. The following sections will provide an overview of both programming methods and describe these differences in detail.

What is ZOS-API?




ZOS-API is an application programming interface, developed for OpticStudio that enables connections to, and customization of, the application. While ZOS-API relies on a COM interface, it is rooted in .NET libraries, and as such programming with the API can be done using any programming language that can access the API libraries, like C++, C#, Python, MATLAB. ZOS-API allows applications to either communicate directly with opened instances of OpticStudio or to run OpticStudio as a background process. For more information about the different communication modes, see Sample code for ZOS-API users.


What is ZPL?




The Zemax Programming Language (ZPL) is a macro language that allows users to write their own program directly within OpticStudio. ZPL can:

  • Automate repetitive keyboard and mouse actions
  • Perform calculations based on OpticStudio data
  • Export data in specific formats
  • Produce graphs and text listings of data

For more information about ZPL, see What is ZPL?



There are some basic differences between ZOS-API and ZPL.

  1. Interfaces

A ZPL macro is a text file. It can be created and edited in the ZPL editor inside OpticStudio. ZPL macros do not require any programming experience. They are easy to learn and provide a powerful tool to execute a series of commands. The following screenshot shows a ZPL macro in the ZPL editor.



ZOS-API applications are written in a programming language that can access the API libraries. Four programming languages are actively supported with ZOS-API: MATLAB, Python, C++, and C#. The following screenshot shows a Matlab code to connect to ZOS-API.



  1. Code execution

ZPL macros are run inside the OpticStudio graphical user interface (GUI). To execute or edit a ZPL macro, click Programming...ZPL Macros...Edit/Run.



For the ZOS-API applications the execution depends on the mode being used:

  • A Standalone Application is an external executable (.exe) file which launches a new instance of OpticStudio as a background process. In this mode OpticStudio is run as a service, with no user interface. Care must be taken to ensure that the maximum number of OpticStudio instances has not been reached.
  • A User Extension or User Analysis is launched from within the OpticStudio GUI and behave in a similar manner to a built in tool or analysis feature respectively. They are accessed through Programming...ZOS-API.NET Applications Group...User Analyses/Extensions.
  • The Interactive Extension is launched from Programming...ZOS-API.NET Applications Group...Interactive Extension. It will connect an external ZOS-API application to an existing instance of OpticStudio.


  1. Syntax

The ZPL is an interpreted “macro” or “scripting” language similar to the BASIC programming language with ray tracing functions.

All ZOS-API programs and extensions are written in an external programming language like C#, C++, MATLAB or Python.


  1. Data access and processing

ZPL macros consist of a series of commands stored in a text file. The commands can be assignments of variables (numeric or string), call functions using keywords, or comments. In ZPL, all data access and processing is based on defined commands. As ZPL is interpreted, it can be slower when running complex calculations than a fully compiled code.

In ZOS-API, data access and data processing are more flexible and powerful. ZOS-API can take advantage of numerical analysis and matrix calculation capabilities of other advanced programming languages, such as MATLAB.


  1. Interoperability

ZPL cannot be called through ZOS-API, and vice versa.


  1. Comparison Table


Interfaces Dependent on the chosen programming language Inside OpticStudio
Code Execution Very flexible (can be an executable, run from the programming language, or embedded within OpticStudio) Inside OpticStudio
Syntax Dependent on the chosen programming language Similar to BASIC; easy to lean
Data Access and Processing

Flexible and powerful data access and processing

Can take advantage of numerical analysis and matrix calculation capabilities of other programming languages (e.g. ZOS-API with MATLAB)

Interpreted language

Can be slower than fully-compiled codes for complex calculations


Differences between ZOS-API and DLL

What is a DLL?

A Dynamic Link Library (DLL) is a shared library. It is a Windows program but it cannot be run directly like an EXE program. It is instead called by another program, here OpticStudio. A DLL is called as required and closed when finished. It makes DLLs efficient in terms of memory as it is only used when required. In OpticStudio, the data sent to a DLL is specified and limited. There are different types of DLLs like user-defined surfaces, user-defined scatter profiles, etc.. For each type of DLL, the data structure can be found in the source code of the sample DLLs under {Zemax}/DLL. For more information about DLLs, see How to compile a User-Defined surface.



The most general difference between ZOS-API and DLL is that the client-server roles are reversed.

  • The ZOS-API script is a client which calls OpticStudio as a server to perform a task. The ZOS-API script can access the OpticStudio interface. Almost any aspects of OpticStudio capabilities can be accessed and run by a ZOS-API script. The API script also contains other capabilities like the Batch Ray Trace.
  • The DLL acts as a server. The OpticStudio client sends and requests specific data from the DLL which it returns to OpticStudio. OpticStudio is in charge of the data exchange. It limits the scope of operations of the DLL.




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



Article is closed for comments.