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 everyone, I'm trying to insert a surface using a DLL file, but it looks like my OpticStudio is not recognize the file. My actions were putting the file in C:\ProgramData\Zemax\DLL\Surfaces (where all the other user define functions located) and then search for this file in the lens data editor. (I followed the instruction from https://my.zemax.com/en-US/Knowledge-Base/kb-article/?ka=KA-01787. Without making any changes) Looking over the list, I don't see my file. What could be the reason for that? What is the right way to use user-defined function/ DLL functions? Thanks a lot! Marta
Hello everyone, I am trying to design Digital Micromirror Device(DMD) in SEQ using 'us_mems.dll'. We know that the DMD behaves as a blazed grating, and also it has diffraction pattern, what I have seen during experiments also. I am wondering how can I simulate the diffraction orders of DMD in ZEMAX. Thanks in advance. Ast
I am having trouble changing settings in the ZOS API when trying to do a single ray trace in Python. My code: ray_trace = self.theSystem.Analyses.New_RayTrace() if ray_trace.IsRunning(): ray_trace.WaitForCompletion() settings = ray_trace.GetSettings() When I try to set the Py to 0, I get settings.Py = 0 *** AttributeError: '' object has no attribute 'Py' How do I change settings for a single ray trace?
Hi, i am new to Zemax and i tried to connect my lense system with Matlab through the ZOS-API interactive extension. As i run the template script the 'TheApplication' Object with all its properties should appear, but thats not the case. It is just showing in which folder it is found and nothing else. Furthermore i do not know how to load the lense system into this matlab file. Is there anything i missed out? If somebody could help a beginner that would be really nice. Best wishes, Julia.
Hello OpticStudio users, Today, I noticed that if I am writting a macro, I need to click on the floppy icon to save it. If I press Ctrl+S, it saves my lens design, but not the macro. This happens even if the focus is on the text editor window of the macro. In other words, if I modify a macro, then press Ctrl+S, and run the macro again, changes are ignored. Am I doing something wrong? I don't remember if it was always the case, but I hope this post will avoid people losing time with this mistake in the future. Take care :)
Is there a way to ignore errors while running a ZPL, and keep it running? I have a ZPL that opens files and some files come up with the following error. Zemax Error Message Cannot determine object coordinates! OK I select OK and the ZPL can continue running. But since I am running through many files this comes up often and doesn't continue until I select OK. Is there a way to ignore these errors and allow a ZPL to continue running? Without having to select OK each time? Thank you,
I am trying to write an interactive extension using the COM (not .NET) framework, and need to change some settings. I have read through (and watched the videos) regarding navigating the API Syntax Help tool, and have spent considerable time scanning the forum and the sample code for guidance. Specifically, I am using the FFT PSF Cross Section analysis, and want to change the Type: to X-Linear or Y-Linear, like this: To try and sort this out, I tried to do the exact same thing as one does in setting the 'Refer To' field in the Standard Spot diagram (it is also an Analysis window with a drop-down menu of fixed selections) I found the following code snippet in example 22: spot = TheSystem.Analyses.New_Analysis(constants.AnalysisIDM_StandardSpot) spot_setting = spot.GetSettings() baseSetting = CastTo(spot_setting, 'IAS_Spot') baseSetting.Field.SetFieldNumber(0) baseSetting.Wavelength.SetWavelengthNu
I know that two codes. i try to Use sample e24 (MATLABStandalone_nsc_detectors). I try to change the word below that codes() d5_set.ShowAs = ZOSAPI.Analysis.DetectorViewerShowAsTypes.AzimuthCrossSection d5_set.DataTypes = ZOSAPI.Analysis.DetectorViewerShowDataTypes.LuminousIntensity ; but it is not work. I want to get Lumens picture can you teacher me? THX
In this forum post, a sample C++ code to read value from a text file in DLL is shared. This is mainly a supplement to the follwoing knowledge base article. The only difference is we will do the similar thing with C++ code to how how to do this in C++ style. How to read a static data file into a user-defined surface In the attachments, a sample code is attached. This code does the same thing as shown in the following forum post. The difference is the diffraction efficiency data is read from a text file. Simulate 2D diffraction grating using customized diffractive DLL We will explain line by line in below. The first thing to do is to define a global variable, which is declared outside of all the functions. As discussed here, during ray-tracing in OpticStudio, the DLL will be called several times. For the global variable, the inside value is unchanged and the DLL can always see the same data in different thread. Our plan is to read data from text file and save it in this global va
Hello Everyone, I am new to Zemax. In my current Project I need to produce a couple (>60000 ;) ) Spot Diagrams for training of NNs. I have used the interactive connection with MATLAB and I can run the simulations in corresponding parameter space. The Problem that I am facing right now is that I cannot export the images from the Spot Diagram Window. I mean I can export the text file of the Spot Diagram (the one with Field Coordinates, Image coordinates, RMS Spot Radius, etc.) but I need the patterns which are visible in the plotted graph. I have already tried to modify the routine in 'MATLABStandalone_22_seq_spot_diagram.m' , but the shape of the resulting graphs are different from the ones Zemax shows. Is there an easy way, like a Export method that I am missing? I would appreciate your help. Bests, Majid
I am writing an Interactive Extension with python (following this KB article). The python script generates a Grid Sag Surface data file (following the format and instructions in these two links: here and here). This file loads properly when manually using the Import tool in the Surface Properties drop-down, as explained in the first link. The goal is to automate this, and I have struggled to figure out the python code to do the import. Based on the second link, I tried the following: gSurf1 = TheLDE.GetSurfaceAt(5) # Surface 5 is the grid sag gSurf1.ImportData.ImportDataFile(gFile) # Load in sag data This did not throw an error. Nor did it work. Nothing changed in the prescription. I have written several interactive extensions in the past, so I think that the basic procedure is Ok. I suspect that the problem is with the syntax of the import statement (which is intended for MATLAB). I searched the ZOS-API Help tool for bot
Hello, i am currently working on a Python program to automate as many process steps as possible in scattered light analysis. I don't have so much experience in Zemax API programming yet and have tried to get familiar with it using the example programs, the knowladgebase and ZOS help. My CAD file is a SolidWorks assembly, which I also inserted without any problems, but I would like to use the Explode command to split it into the individual parts for a better path analysis. Here my question is how to unzip my file correctly and if there is a more detailed article than the videos about the ZOS API Help, because this is not enough for me to understand the command structure. A second point is, I would like to have my data from PathAnalysis available as data in Python for evaluation, here I also did not manage to understand the program structure. So far I have only been able to make it useful by saving it as text first and reading it in afterwards. With kind regards Christian
Hello! I am trying to plot spot diagrams as I change Zernike values using MATLAB. I spent a lot of time to create a for loop, but the same diagrams are printed over and over again. I attached my MATLAB code and zmx file. Could you check this and let me know what the problem is?
Dear support team, I am working with a complex off-axis optics with several stray-light baffles. I need to determine the vignetting as a function of the two field coordinates. The first surface of my afocal system is the aperture stop. With vignetting I mean a geometrical quantity defined as the number of rays from one field that reach the image divided by the number of rays that pass my aperture stop. I think this is basically what the Zemax 'Vignetting Plot' does. But: 'This feature is appropriate for rotationally symmetric lenses and fields' only. The Footprint Diagram determines the 'percentage of rays through', which should be the same. Is this correct? Is there an Operand available, that calculates the vignetting according to what these two plots do and which I can calculate over a 2D-field with ZPL? I found the IMAE Operand: 'The IMAE operand estimates the efficiency of an optical system by launching many rays into the entrance pupil; computing the fraction of rays t
Hello! When calculating the FFT PSF, I sometimes get the error message 'Computation aborted, invalid results'. When I change the PSF sampling, the error disappears. It is probably linked to a user defined surface (based on the multizone asphere surface example) combined with specific values of decentrations of the optical elements. Do you have any ideas about the meaning of the error-message and how to debug it / get rid of it? I am saving the FFT PSF window within a ZPL macro. Is there a way to do error-handling in the ZPL macro? (E.g. if the error occurs, the sampling of the FFT PSF calculation will be decreased and the calculation repeated...) Thank you!
I am using a ZPL script to determine COM positions of many spots with the CENX,Y operant. To set the field positions, I need the 'SETSYSTEMPROPERTY' command followed by an 'update'. Now it turns out that the 'update' requires by far more time than all the ray-tracing. This causes huge runtime issues. My script is running for weeks. Is there a more efficient way to set the field positions in ZPL w/o an 'update'command?
I’m interested in automating a couple of simple steps using ZPL. I don’t find a reference table of the names of different parameters in ZPL in the Help. How do I print a particular merit function result e.g. CENX at a particular station, and how do I change the value of a Coordinate Break’s “Decenter X” or “Tilt X” etc.?
Hi, I'm running Zemax Optic Studio Professional, version 20.2.2. Whenever I'm working with large pixel arrays, or high (> 1024 x 1024) sampling in physical optics propagation, and my detector viewer/beam file viewer is set to text view, I get a message box saying 'Text is too long to display. Use Copy All or Save As' to retrieve the entire file'. This message box doesn't cause a problem as I'm exporting the data in a macro anyway, but it means that during a long macro where I'm running POP multiple times, I have to constantly watch OpticStudio as it pauses the macro until I dismiss the message box, which is obviously impractical. Is there a way to either a) Increase the maximum allowed text file to be displayed within OpticStudio, or b) Suppress the message box, as the data export is absolutely fine Thank you!
Hello, I am doing a polarizaiton analysis and am running into an issue when it comes to updating my surfaces. I have a short macro that updates the tilt about x for a coordinate break before a mirror, and the tilt about x for a coordinate break after a mirror. Then, I am using the OPEV function to get the transmission of a surface further in the system. The problem is, when I use the macro to udpate the tilts, the results don't show in the OPEV function unless I manually refresh the results. This will not work for me as I am working with a very large data set and thus need to be able to do it without manually refreshing. Just a simple example of the setup is given below. SETSURFACEPROPERTY 8, 10, 3, 3 # sets the tilt about x before the mirror (surface 9) SETSURFACEPROPERTY 10, 10, -3, 3 # resents the tilt about x for the whole system, esentially just tilting the mirror in the whole system code_coda = OCOD('CODA') # defining the merit function code used to get th
OpticStudio is no different from any other software in using floating-point representation for storing numbers other than integers. Although the accuracy is very high, sometimes a number like 0.7 can be stored internally as a very close approximation, like 0.700000000001712 or 0.6999999999998394 for example. For calculations these differences are usually acceptable. The differences are generally confined to the digits near the limits of double precision storage anyway. Be very careful, however, using numbers like these in a comparative, like checking if a variable is less than another. In Zemax Programming Language (ZPL), OS operands, and some types of displays (bar charts), particularly with discrete data divisions, you might see unexpected results. For instance, in the following code, there is a big difference between A being 7.1 and A being 7.099999999981728. IF A >= 7.1 PRINT 'Success' ELSE PRINT 'Fail' For similar reasons, the use of non-integers as indices in a FOR-
Hello everyone, I am a grad student at the University of Arizona and I am working on a project that will require me to make use of the MATLAB ZOS-API feature. While I have never used this feature before, I familiarized myself with enough of it to at least get started. I am running into the peculiar problem that when I click the feature within Zemax (either standalone application or interactive), instead of generating a Matlab code and opening the Matlab application, it instead opens and displays the code within Mathematica. I only recently installed Mathematica on my computer, and I do recall that before it was installed, Zemax would open up the Matlab application just fine. Interestingly, now I cannot get it to open up through Matlab. While I thought one solution would be to copy and paste the code into Matlab and then track down the directory that Zemax created within the ZOS-API Projects folder, this does not seem to be working. If anyone else has experienced a similar
Is it possible to calculate the 'field Type' 'Angle' (Code 0) from the 'field Type' 'Real Image Height' (Code 3) with a ZPL script? It is basically what the Zemax 'Field data editor' offers with the 'Convert to' option. However, I do not need to *convert* the field type, but just have to determine the value. With 'Single Ray Trace' as well as with the operand 'RAID', I only get one angle. But I need the two angles as defined for the 'field Type' 'Angle' Thank you and best regards, Christof.
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.