Share your solutions or ask questions about the ZOS-API, ZPL, or DLLs. Code shared in these spaces is not reviewed by Zemax except for the Code Exchange.
Hi guys,I decided to section the ZPL task to avoid confusion because I have about 100 of these macros to write. Compute and plot MTF, plotting all fields in one plot (to a maximum of 20 fields). Compute and plot the MTF over a linear field for a specified set of spatial frequencies. Compute the MTF over the field of regard (FOR) for a specified spatial frequency and a specified field point Compute and plot the radial, tangential, or average of radial and tangential MTF over the FOV for a specified spatial frequency Compute the MTF at a given spatial frequency vs. the change in a specified lens parameter. Compute the MTF at a given spatial frequency vs. the change in a specified lens parameter. The parameter minimum and maximum values may be entered as actual values or as deltas. Plot the two-dimensional MTF for the specified field points, zoom positions, and through-focus positions. Plot the optical MTF cascaded with the detector MTF to get the combined MTF for the system
Hi,I am trying to use a Matlab script to trace rays and read only the rays that hit my detector after a ghost reflection.I have been trying to save the rays and use a filter to select only the ones I want. Unfortunately, I am not able to read the detector using the ray database. Does anybody have a tip to solve this issue?Thanks,Daniel
Dear all,I have a WinForm/WPF project where I want to use ZOS-API.The console application from ray tracing example file works fine. However, when I added ZOS references (ZOSAPI, ZOSAPI_Interfaces, ZOSAPI_Nethelper) to the WinForm project (compiled for x64), I got a null reference, like so:I’ve made minimum modifications to the original example of the ray tracing program. Basically, I just wrapped it into a separate class and removed the Main method, because the WinForm project already has an entry point.The program could be succesfully initialized, which means ZOSAPI references linked to the project:Found OpticStudio at: c:\program files\zemax opticstudioHowever, after new connection created, “TheApplication” reference is null:IZOSAPI_Application TheApplication = TheConnection.CreateNewApplication();I appreciate it if anyone knows the cause of this null reference. Regards,Mykyta
Hello. I am currently trying to extract the POP output beam data with the ZOS API with not much luck. I would like to pull the data from the POP itself rather than the mfe since i have noticed that the mfe will not update POPD operand values with the input POP settings from an astigmatic gaussian POP. It seems that in the articles I have looked that the the GetResults() from POP will give you the header value and the datagrid pixel value. Since I am trying to get the Raleigh Range, Waist Location, and Waist size data of my beam at the out put place I thought that maybe pulling the data from HeaderData.Lines would work since the beam data is in the line after the irradiance data (line 6t), but when I try this I get an error saying that 7 is past the limit of lines, so I am not sure where to pull this data? I am also noticing that there is a slight bug in the POP data where if propagating X and Y separately, like in my case, it will only output pilot beam data for just x vs for x and
It is common for illumination design to have complex shapes which are difficult to describe by a mathematical formula. For example, custom collimators, waveguides, reflectors, and so on could be represented by freeform curves. When such optical components are designed in a CAD program, we can't optimize their shape in Zemax after importing CAD files.To overcome this issue, I provide an example of how to convert CAD data of a TIR lens into a parametric surface and optimize it for light collimation.In this example I’m using TIR lens. It consists of TIR surface and refractive surface, as shown below.Reference: Pencil of RaysFirst, we will fit TIR surface.Zemax has a Freeform Z object, which is formed by drawing a cubic spline curve through a series of points in the YZ plane:Our target is to retrieve these YZ pairs from a solid model cross-section via cubic spline interpolation. Spline interpolation can be done in python using scipy.interpolate.CubicSpline(Z,Y):Cubic Spline InterpolationAf
Hello everyone,In the full-field aberration map, the sampling value of the field of view has a maximum value of 20. When I want to find the minimum point of an aberration, I often cannot get it precisely because of the lack of precision.I've read the question and the response below, and I am confused that if we use the ZERN operand to read the zernike coefficient value, then a lot of fields need to be setby using zosapi to calculate in matlab. After trying, I found that the fields can only be set around 2000 at most, and the speed is slow. So I want to know how to get the aberration of any field point, and if there exsits an interface like this, the optimization can be done to find the exact position of the minimum value.
Hello. I’m interested in running optimization targeting to get a specific beam shape on image. The beam is generated using POP Gaussian angle. The analysis i want to run requires a macro code. For that I’m going to use the ZPLM operand. My question is how do I read POP analysis Text data tab with the ZPL? I want to process the data and to return the macro result to the merit function ThanksRaphael
GetAllDetectorData() and GetAllDetectorDataSafe() are both methods that can be used to retrieve detector data for a specified detector object. The main difference between the two methods is that GetAllDetectorDataSafe() returns a two-dimensional array of double values double[,] that contains all the detector data for the detector object, while GetAllDetectorData() returns a boolean value that indicates whether the detector data was retrieved successfully, and one-dimensional array double . GetAllDetectorDataSafe() does not require the input of numPixels and detectorData, whereas GetAllDetectorData() requires these parameters in addition to (detector) ObjectNumber and Data(type).Check the examples to use the two methods: For python: TheNCE = TheSystem.NCEDetObj = 4obj = TheSystem.NCE.GetObjectAt(DetObj);numXPixels = obj.ObjectData.NumberXPixels;numYPixels = obj.ObjectData.NumberYPixels;DetRectangleData_FluxArea = TheSystem.NCE.GetAllDetectorDataSafe(4, 1)for x in range(numXPixels):
Dear support team, it seems that a 'Print' statement in ZPL is suppressed during the script is running. Then at the end of the script all print statements are executed at once. I guess, this is a kind of optimisation? However, I am running large scripts and I would like to see the progress in the command window . So I would like the print statement to react directly when it is called. Is this possible? Thank you, Christof.
API (Python and MATLAB Interactive Extension) Calculate the Ray Transfer (ABCD) Matrix for thick Lens
To compute the ABCD matrix, OpticStudio traces rays over a very small region centered upon the reference field position. Usually, this is the center of the field of view. OpticStudio allows selection of which field position to use for reference.By default, OpticStudio sets the corner of the field grid in object space to be at the maximum radial field distance. Because object height is linear with the tangent of the field angle, the full width of the field when angles are used to define the field is given byWhere θr is the maximum radial field angle at the corner of the field.The ray coordinates in image space for the very small field of view are used to determine the ABCD matrix components. The use of an ABCD matrix allows for coordinate rotations. If the image surface is rotated, such that a y object coordinate images to both an x and a y image coordinate, the ABCD matrix will automatically account for the rotation. The grid distortion plot shows the linear grid, and then marks the ac
I am trying to view/export the zernike data of my system using Matlab and the API. Currently my code reads: And I don't know what to do from here. The data comes to Matlab in an IAR file type, and I don't know how to extract it. Thanks, Stephen Chapman
I started modifying the boilerplate code included on this page: https://support.zemax.com/hc/en-us/articles/1500005576882 Looking through the ZOS-API help from the Programming Tab in OpticStudio I can tell that there are some differences between the way the code is implemented in the .dll versus the way it is described in the help files. How do I access the API for the methods and classes inside the .dll file?
I am following the example (CSharpStandalone_04_pull_data_from_FFTMTF.cs) to get FFT MTF data like below; newWin.ApplyAndWaitForCompletion();IAR_ newWin_Results = newWin.GetResults();It works fine in my computer. But the same copy returns ‘null results’ from other’s computer.No idea where I should look into for debugging.Appreciate your kind advice.
I tried to use the original Gaussian.cpp in Visual Studio 2019 to create a dll project. I created a default dll project and copied the Gaussian.cpp and tried to build the file. The header file is left empty. The build was successful but when I tried to load into Zemax, it gives error saying cannot load DLL as in the attachment.
Hi Frequent Posters,As I’m sure anyone who regularly answers questions on here, you can at least run across a response not saving for one reason or another. Zemax has a placeholder warning saying “be sure to wait for your attachment to finish uploading before you submit, or you may lose the content of your post”. The only problem is there is no indication from Zemax that attachments are still uploading. So, if you have a few images and one hasn’t uploaded (for whatever reason), you lose your entire post. This is very frustrating, especially if you have a few paragraphs with several images (I’ve personally lost probably over 8+ hours of creating responses because of this).The CKEditor which the community forum uses unfortunately doesn’t have client-side autosave via localStorage (the editor only has a server-side autosave which kinda defeats the purpose of losing content because it’s not sent to the server).I wrote a tiny Chrome (and Edge) extension that will auto-save your content
Hi, I've recently experienced an issue when using ZPL/Zrdplayback command for optimizing a non sequential system. The local optimizer/orthogonal descent, worked fine, but the two global optimizers (Global search & Hammer) stopped at the start of the optimization process with the following error message 'Unable to save file...'. I've found a design file in this forum showing the same behavior (please check the attached file). I suspect that the problem arises when several variations of the initial model are generated and attempt to create and/or read the rayfile from the ZPL macro. Could you please comment and propose a fix that would ideally, preserve the call to zrdplayback? Thank you
Hi Sir/Madam,I am trying to get the peak irrandiance through ZPL language, but seems do not have command fit my purpose.I am thinkging if I could use NSDD to get flux value in position space for each pixel# and compare each value with a command like “maximun” to get the peak one in a array, then I still could reach my purpose. But is there any command for me could do it to get maximun value? and how should I use it? SincerelyDavis
This Surface Scatter DLL uses an external data file with spline fit points to generate a rotationally symmetric spline-fit scatter function. Allows for quick/easy custom scatter definitions to be implemented. Spline function is defined via polar angle (with theta=0 centered on the specular ray). External data file consists only of 2 columns: polar angle, and relative radiance.Authors: Zachary Derocher Tim Gustafson - Zemax Click here to download Date Version OpticStudio Version Comment 2020-01-15 1.0 - Creation
Dear community, I would like to access the tilt/decenter tool from the sequential surface editor via the ZOSAPI interface. In particular, I would like to do so with Python. I searched the documentation but I could not find anything about this tool. Other tools, such as the conversions between global and local coordinates area acessible via ZOSAPI. Did I miss something or is the tilt/decenter tool not yet integrated in ZOSAPI? If so, are there plans to do so?Best regardsBenjamin
Hello, I created a ZPL (ZPL02.zpl), it seems to work if I run it directly through Programming>Edit/Run, but not inside the merit function.PRINT "worst case : ", worst_colorOPTRETURN 0, worst_colorThose two lines do not give the same value. The first one gives a correct value. In addition, when I call this ZPL through the merit function, it does not update the output value.What should I do?Thanks in advance for your help,
Hello everyone,I have to simulate the propagation of a supergaussian beam with a M2=46.9 through the Physical Optics Propagation but I don’t know how to define the beam. I tried to use the top-hat beam, which is a good approximation for my purpose, but its divergence (in POP) does not match the divergence of a supergaussian beam. Thanks for your help.
Hi Everyone (+ @Allie & @Sandrine Auriol),There is nothing inherently wrong with the modern version of PythonNET but there were some changes that the PythonNET team made to inheritance. PythonNET is now more in line with C# where you have to use the proper static variable type (my best guess is this is better handle multi-threading and easier integration of Python into C# using the GIL...the opposite of what we’re trying to do with the ZOS-API).In PythonNET 3.x, when a method returns a interface with inheritance, the returned variable becomes a type of the parent interface (not the child interface). For example, if you use the GetSettings() method for an analysis window, all settings have IAS_ parent interface and a child interface with the actual settings for the analysis window. In previous versions of PythonNET, the returned variable was dynamically typed and PythonNET attempted an implicit conversion from the parent interface to the child interface. So the following lines o
This DLL models a Vortex Phase Plate. It is useful in laser applications to convert a Gaussian laser beam into a donut-shaped energy ring. For more information, check the following links:https://www.holoor.co.il/wp-content/uploads/2017/11/vortex_zemax_tutorial.pdfhttps://www.holoor.co.il/application/optical-vortex-phase-plate-application-notes/https://www.holoor.co.il/optical-calculator/vortex-lenses/ The Vortex phase plate is a phase surface: Click here to download Date Version OpticStudio Version Comment 2021/03/20 1.0 - Creation
Is there a list of ZPL reserved terms, such as.…$FILENAME()$DATE()I know that these are not high priority terms like the optimization operands, but they are useful when crafting output text. Others might be PATH, and some of the System Parameters. Thanks
Dear OpticStudio users, I have created a GitHub repository with a template Python script to write binary source files: https://github.com/Omnistic/BinarySource_OpticStudio I'm hoping this will make it easier for you to write binary sources for OpticStudio in the future. As a reminder from the help file, binary files are 30% as large as equivalent text files, read about 20x faster, and can be left on disk consuming only little RAM. The repository also includes an example script to generate stigmatic Gaussian beams as described by P. Colbourne in his webinar. By generating a binary source file, one can visualize the propagation of a non-sequential stigmatic Gaussian beam given its waist parameters. Note that the beam needs to intercept the surfaces sequentially, this is a dummy example for visualizaiton only. An OpticStudio archive file is also included for demonstration. This archive contains the Gaussian beam shown in the layout below (x_waist = 1 um, and y_waist = 2 um).
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.