Find and share your best practices for using the ZOS-API here!
- 284 Topics
- 855 Replies
Hi!Working with a task where an old ZPL macro should be converted to a standalone application in C++ (using ZOS-API). I have encountered several macro commands that I cannot find any description for in manual/help.Is there anyone here that have the knowledge of what the corresponding calls with ZOS-API would be?Object_distance_orig = THIC(0)number_of_surfaces_orig = NSUR()IMA_SURF_NUM = NSUR()Lens_Configuration_orig = CONF()number_of_configurations = NCON() Thanks in advance!
There is a common error that can result from running 32-bit user extensions and user analyses in OpticStudio. The error may manifest in odd ways where an extension fails to open or has an unexpected user interface. When using the ZOS-API, it will engage a dynamic-link library (DLL) called the ZOSAPI_NetHelper.dll. The function of this DLL is to help the user extension locate the installed version of OpticStudio. OpticStudio versions older than 2023 R2 suffered from an issue where the NetHelper DLL could not properly search the Windows registry if the target bit setting of the user extension did not match OpticStudio. Since OpticStudio is a 64-bit program, it might not be found if a user extension was compiled as 32-bit, which is the default for common compilers.In short, if a user extension is compiled as 32-bit and tries to use the NetHelper to find the installation location of OpticStudio, it may fail and deliver the above error message: “OpticStudio cannot be found.” If you possess
I am using a standalone Matlab API in sequential mode to load a .zmx file and do various analysis with data handed back to Matlab. This works perfectly except when I include a blackbox element. The .zmx file loads and I can modify and query it in standard ways. When I execute any analysis (e.g. a PSF calculation), the structures returned are empty. I don’t get an error message, just empty results. If I replace the blackbox lens with a stock element, everything works again. I can execute the analysis in OpticStudio by loading the .zmx file (with the blackbox) and selecting the analysis from the menu. Are blackboxes incompatible with the API or is there something special you need to do, maybe telling the blackbox file to load after the .zmx file is loaded?Thanks in advance for any pointers!
Export Analysis, Graph and Layout JPG using ZOSAPI Interactive Extension Python and Matlab using ZPLM
We can use Python or Matlab Interactive Extension to execute Macro using ZPLM. Please take these stepsWrite a ZPLM code that can export JPG or BMP from a given window. GETSYSTEMDATA 1 EXPORTJPG 1, "C:\test\JPG_file\3DLayout" EXPORTBMP 1, "C:\test\JPG_file\3DLayout" OPTRETURN 0 You can read more about ExportJPG and EXPORTBMP in our help files: The Programming Tab > About the ZPL > KEYWORDS (about the zpl) > EXPORTJPG Save the file as ZPL55 or ZPL”Any Number you like”. Use this ZPLM in Merit Function Editor. In case if you like to know more about using ZPLM as Operand in Merit Function Operand. Please check this KBA: Optimization using a ZPL Macro: the ZPLM operand. Save this Merit Function as “ExportImage.MF” in folder Zemax LLC\Documents\Zemax\MeritFunction 4.Write Python or Matlab Program to run the ZPLM through Inter
Hello everyone, I use Zemax 22.3 professional and have the following problem:I build a simple toy model in the NSC Editor consisting of a perfectly collimated light source (1mio rays) and Detector (150x30 pixel).I have two scenarios which should give the same resultsI get the incoherent irradiance over the Zemax API (in Python) with the function “GetAllDetectorDataSafe()” (no detector smoothing activated) I get the detector intersection points and intensities of each ray with the ZRD datareader function BatchRayTrace.ReadZRDData() and calculate the detector distribution with a two dimensional histogram (e.g. with numpy.hist2d())While the distributions definitely correlate, scenario 1 looks significantly smoothed compared to scenario 2 (I checked and there is no energy loss of the rays between the source according to the ZRD datareader and the detector as expected and also within the Zemax GUI the distribution looks smoothed).If I interpret the Zemax manual correctly this should not be
When dealing with non-Standard surface types, you typically have access to extra parameters that are specific to that surface. For example, the Coordinate Break surface provides inputs for Decenter X, Decenter Y, etc. Coordinate Break surface type with the extra data parameters highlightedTo access these parameters in the API, our sample code offers two options:Access a parameter based on the parameter number. A typical command for this may look like the following: decenterX = TheSystem.LDE.GetSurfaceAt(1).GetSurfaceCell(ZOSAPI.Editors.LDE.SurfaceColumn.Par1).DoubleValue; Access a parameter based on its column number. A typical command for this may look like the following: decenterX = TheSystem.LDE.GetSurfaceAt(1).GetCellAt(12).DoubleValue;In both of these cases, you will need to have prior knowledge of the location in the LDE of the parameters you want to change. Or you will need to query the “Header” of the column you’re working with to confirm the parameter is correct. There is a th
Hi everyone, I created a Matlab script which can both output the results txt file via ‘GetTextFile’ and read the results of a Huygens PSF analysis directly. The problem is that these do not match. Excerpt from my code:newWin = TheSystem.Analyses.New_HuygensPsf();...newWin.ApplyAndWaitForCompletion();newWin_Results = newWin.GetResults();data = newWin_Results.DataGrids(1).Values.double;newWin_Results.GetTextFile(outFolder) Txt File Data Snippet:data variable above snippet:Is “DataGrids(1).Values.double;” the proper way to extract this information from GetResults? The text file also matches what standalone OpticsStudio provides me so I am taking that data to be the truth.
I’m writing a user-defined merit function operand in C++ and would like to read the header lines from an analysis window (and then parse the results to extract numerical values of interest). For example, in POP, the header contains several useful numbers related to the analysis results. Using Matlab, this is fairly simple as @Allie discusses here: However, it appears that in C++ the header lines are passed using SAFEARRAY. There is one example (#23) that shows how this is done for numerical arrays (see below). Just curious if someone might know how to do something similar for the header lines? Is it possible to get the header lines in the form of a string array? If so, a simple example would be greatly appreciated! Thanks,Jeff
Hello,i am using Zemax Optics Studio 23.1 and trying to run the python example files included in the “Zemax\ZOS-API Sample Code\Python” directory.While others seem to work, when trying to run “PythonStandalone_23_ray_fan_native_manual_comparison.py” i get an error.----Traceback (most recent call last): File "c:\ex\PythonStandalone_23_ray_fan_native_manual_comparison.py", line 262, in <module> ray_settings.Field.UseAllFields() ^^^^^^^^^^^^^^^^^^AttributeError: 'IAS_' object has no attribute 'Field'Exception ignored in: <function PythonStandaloneApplication.__del__ at 0x000001D4F7E9F880>Traceback (most recent call last): File "c:\ex\PythonStandalone_23_ray_fan_native_manual_comparison.py", line 72, in __del__TypeError: 'MethodObject' object is not callable----I run the original file without any changes. Could somebody please possibly advise if eventually the API did evolve and this particular example file is no more compatible?Best regardsDimiter
Hi Team, I have a python program that finds the shifts in the position of spots (consider it as focused spots). I want to connect my python program with Zemax (Through Interactive Extension script) My question is, how do I connect specific feature (Say- Geometrical I mage analysis or Spot diagram) with python? Also, is there any changes I should be making in my python code, to connect with these Zemax features? Thanks in advance. Regards,Arun
Hello Experts, I want to run image simulations over an entire dataset of images based on the lens design but image simulations take too long. Is there a way I can do that by using the Huygens PSF and an input image using python (maybe convolution)?To give a background, I have created 2000 field points and extracted the corresponding PSF as .txt files. These files represent one quadrant of the image plane and can be mirrored to create the spread of PSFs over the entire image plane. Then divide the inpput image into a grid of 8000 blocks and convolve each block in the grid with the corresponding PSF. This could create the output image.Is there a better way to do it? I ask becuase I am not able to change the settings of the image simulation while using python API and running the simulations automatically.The goal is to create a large database of images that are output of a certain lens model.Any recommendations are welcome. Thanks,Amit
Hi all,I am using BatchRayTrace with the ZOSapi in OpticStudio 230724 and python 3.9.Following example 22, I am able to raytrace and extract the results into x_ary and y_ary. Subsequently I calculate the geometric radius using x_ary and y_ary. So far so goodAfterwards I want to use BatchRayTrace with a different surface and calculate the geometric radius again at the updated surface.Problem: I cannot update the “toSurface”. The first call of raytrace.CreateNormUnpol(max_rays, ZOSAPI.Tools.RayTrace.RaysType.Real, surf_i) seems to define the “toSurface”. It cannot be changed even, if I close the tool and open a new one with the new surface: It always calculates the exact same output as before. Does anyone tried to update “toSurface” of the BatchRayTrace -Tool in a loop before?Is there anything else to do to update the “toSurface” in addition to closing the Tool? Here is my code snipped: # Define batch ray trace constants hx = 0.0 hy = 0.0 num_fields = TheSystem.SystemData.Field
It is a good practice to fail extremely loudly - if there is some issue, don't leave it up to the caller to detect the problem. Halt execution, and please throw an error. We've been using CAD files, and the server we have been using the ZOS API didn't have Solidworks installed. Because of that, the ZOS API just silently ignores those CAD files - no logging, nothing. As a result, we have months of simulations that have produced bad results. The answer I've gotten before is 'We rely on the user to handle errors'. This is terrible UX. How am I supposed to find problems? I make an exhaustive checklist that is 300 items long that validates each ZAR file the API ingests? How do I make that checklist in the first place? I don't see how I could have noticed this CAD issue. At the very least, please print out potential issues to the console. The best option for UX would be to throw errors.
Here’s a snapshot of the API documentationWhen tracing rays, the following parameters are not documented: double exr, double exi, double eyr, double eyi, double ezr, double eziThey are defined here:and here in the DDE documentation and here in the C codeand here by Julia (link)So… what’s missing?Well, Julia provides us with code that works. I am inferring the Ex and Ey set the amplitude of the electric field. That along with phaX and phaY set the polarization state. Exr, Exi, Eyr, Eyi, Ezr, Ezi have been used to specify the electric field of a ray in DDE and custom surface DLL code. They are often outputs, not inputs. If they are inputs then they seem redundant.So…Do we always set them to ‘0’? If we give them a value, will it override Ex, Ey, phaX and phaY? Generally Ez is reserved for rays approach off axis, which means if you specify this parameter, you should not also specify Hx, Hy, Px, and Py.This is all quite complex. What is the best guidance?
Hello,We are urgently looking for an alternative to ZPL-GETZERNIKE using ZOS-API.The point is that we cannot tell “TheSystem.MFE.GetOperandValue(MeritOperandType_ZERN, “ the maximum term of Zernike.“TheSystem.MFE.GetOperandValue(MeritOperandType_ZERN, “ always develops only up to the given coefficient :-(MAny ThanksHans-Jürgen
Hello. I have been learning how to use ZOS-API in Standalone mode with Python for a while now, but it seems that custom operands for optimization are only available using C# or C++. I have started working with C# (despite not knowing the language) and I have managed to get custom operands to work using this. Currently, I am working on connecting C# to Python so I can run my previously written scripts and then optimize the system based on some values calculated in Python. My current pipeline looks something likeUDOC operand runs Python script Python script runs an instance of Zemax in Standalone mode and calculates some value Value is sent back to UDOC operand Zemax retrieves valueThis setup somehow manages to work with just getting the value from Python into Zemax in the Merit Function Editor, but actually using the UDOC operand for optimization doesn’t seem to work and is also incredibly slow. A single cycle in the optimization loop can take over two minutes while retrieving the UDOC
I’m working on running multiple POP simulations and they each take about 30 minutes. I’m debating trying out the python package “threading” to try and run multiple runs at the same time in order to save some computing time. Are there going to be any limitations on the Zemax side of this equation?
Hi is have a few Beginner Questions about ZOSPy.Sofar the few times I needed to do combine Zemax with Python I used PyZDDE.PyZDDE doesn’t seem to work any more with the Ansys Version of Zemax, so that I now have to switch.I just started to look into ZOS-API and try to wrap my head around how it works.For the start I have a few simple questions about ZOSPy:How do I control to which Zemax File ZOSPy connects? Does is it just connect to what ever Zemax File is open? What happens if several Zemax files are open? Do need to put the Phython Skipt/Jupyter Notebook in the same directory as the Zemax File? Do I need to switch Zemax into Interactive Extension mode before Running the Python script?
I want to start and optimization over the ZOS-API and output some status values (more than the merrit function itself) during the run. It seams that the variable variables are not updated during the optimization but only when the optimizsation ends or is canceled. It seams there is no API interface like in the GUI (“Auto Update”) for the optimizers and even in the GUI this button seams to be more gui related than belonging to a file (at least it is not saved within the file).Amnybody has an Idea how to solve this ? Any chances for a feature update in Zemax ?
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.