Ansys Learning Forum Forums Discuss Simulation Optics To create ZPL for the non-sequential calculations. Reply To: To create ZPL for the non-sequential calculations.

Ethan Keeler
Ansys Employee

 

 

Hi Navaneeth,

Thanks for your question! As you pointed out, there are two ways to create automated routines in OpticStudio, using ZPL or the ZOS-API. Which to chose depends on a few factors. ZPL is much simpler and easier to get started with; however, it is more limited in functionality. On the other hand, if you are comfortable with programming using Python, MATLAB, C++, C#, etc., then the ZOS-API might be a good route because in the long run it will give you more control over OpticStudio. Using the ZOS-API also lets you more easily manipulate and process the data using third party libraries (e.g. MATLAB). 

To get started with ZPL: Introduction to Zemax Programming Language (ZPL) – Knowledgebase
To get started with the ZOS-API: Understanding the basics of ZOS-API structure – Knowledgebase (zemax.com)

As for your specific question, I’ll show you the basics of both methods.

ZPL: You will want to use SETNSCPOSITION to change the Z location (more information in the Help File, The Programming Tab » About the ZPL » KEYWORDS (about the zpl) » SETNSCPOSITION (keywords)), and as an example: 

SETNSCPOSITION 1, 4, 3, 115

To get the detector data, you will want to use OPENANALYSISWINDOW and then either EXPORTJPG (to get an image) or GETTEXTFILE (to get the data in text form). You can find a good example of this here: Saving detector series data / img with ZPL | Zemax Community

ZOS-API: 

To change the Z-postion, in the ZOS-API, you would call something like this (for more information on the command, check out the ZOS-API Help File):

TheSystem.NCE.GetObjectAt(4).ZPosition = 115;

For the detector data, this is a little more involved as I mentioned, but there is a detailed explanation here: Methods for extracting detector data through the API | Zemax Community.