Skip to main content
Question

Run User Extensions from MATLAB or Python

  • November 5, 2025
  • 1 reply
  • 27 views

reza

Hi All! I have created an User Extension using C++ and it has built .exe file and can run it when I open Zemax. Is it possible for me to run the user extensions in MATLAB or Python using any ZOS API function?

1 reply

MichaelH
Ansys Staff
Forum|alt.badge.img+2
  • Ansys Staff
  • 402 replies
  • November 5, 2025

Hi Reza,

In general, the ZOS-API can be run through any software that also supports the .NET Framework.  With C++, this is done through a COM layer, for Matlab, this is done through a proprietary interface and for Python, this is done through the pythonnet library.

Each ZOS-API script has a different connection mechanism to connect the language in question to the ZOS-API, so while most of the code can be easily re-used from language to language, the hard-coded connection cannot be re-used.  So, if you have a EXE that was compiled with C++ (especially if it was a User Extension and not a Standalone Application), you will not be able to run this through a different language.

A compiled User Extension has to be directly called via the GUI in OpticStudio.  OpticStudio itself has to be placed in a “waiting” state for the User Extension to execute and if OpticStudio is not in this “waiting” state, then the User Extension cannot establish the connection.

In summary, while code can typically be re-used and modified from language to language, the connection method cannot be re-used.  If you need to run something through Matlab or Python, you should use the templates from OpticStudio as a starting point and write the code yourself.