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.
This User-Defined Surface DLL provides a realistic model of relief-type diffractive lenses based on zone-decomposition. Using zone-decomposition, diffraction into multiple orders can be accurately considered at once, and this method inherently accounts for wavelength dispersion and diffraction efficiency by modelling the actual shape of the diffractive element.Application examples include the creation of advanced intraocular lens models, where the different orders are designed to provide sharp vision for multiple viewing distances, thereby substituting accommodation of the natural crystalline lens.This application is discussed in detail in the following knowledgebase article:Realistic modeling of relief-type diffractive intraocular lenses using User-Defined Surface DLLs – Knowledgebase (zemax.com)Source code download link:Download files (DLL Surface): Relief Type Diffractive Surface | Zemax Community
Is it possible to do a ZOS-API Interactive Extension with Excel VBA?I’ve been able to do a standalone with examples from this forum. This works: Set TheApplication = TheConnection.CreateNewApplication() Set TheSystem = TheApplication.CreateNewSystem(SystemType_Sequential)This does not work (get the VBA error message “Object variable or With block variable not set” for the second line which seems to say that TheApplication is not being Set properly): Set TheApplication = TheConnection.ConnectAsExtension(0) Set TheSystem = TheApplication.PrimarySystemI’ve also been able to do an Interactive Extension with MATLAB from the boiler plate code (similar to above) generated by OpticStudio … just can’t seem to get it to work in Excel.Thanks.
Hi! I’m calculating the energy inside a surface with LEDS with different detectors: volume detector, sphere as detector, volume pipe as detector… but I can’t get the same values across them… I don’t know why if I hace the same system…From objects as a detector I get total power, but from volume detector total flux (all of them in mW); is this the same?When I take a value from the matrix in volume detector, what is this? flux, power¿?This is my file, I calculate the three detectors individuallyThanks in advance,Carmen
Hi,I’m using the Path Analysis feature (run from Matlab) to analyze how the light is going through a system. Path Analysis is a great feature!What I’m noticing is that if I add up the number of rays in the path analysis rows, they equal to the number of rays in the ray trace / and in the layout. However, if I add up the powers in the rows, there is a total loss of about 1.8%. I currently do not have any coatings set on the various components (struggling to get that to work for some unknown reason or the other). Just mirror/reflector and absorbers.Is there an atmospheric loss built into Zemax due to the air the light passes through? I tried setting the air pressure to zero in the System Explorer/Environment to try and simulate a vacuum, and it didn’t change anything. And, if there are air losses, I’d like to control them or set them to zero and calculate the losses numerically. Thanks!
Hey Community,I’m starting this thread as a place to document some of the “pitfalls” of the ZPL language. The ZPL is extremely powerful but since OpticStudio is trying to create a new language, the parsing is sometimes problematic.Variable NamesYou can actually assign a value to a number (the ZPL treats the number as a variable name). So while OpticStudio won’t throw an error, you should be very careful when picking variable names:PRINT 1 + 2 # answer is 31 = 2PRINT 1 + 2 # answer is 4FOR LoopsThere is always round-off when dealing with decimals and this becomes especially true when trying to use a decimal step size in a FOR loop. Rather than using decimals as either the start, end or step size, you should keep these as integers and convert to decimals inside the FOR loop:RecommendedFOR i = 0, 10, 1 px = i / 10NEXT Not RecommendedFOR i = 0, 1, 0.1 px = iNEXTSpeed Up CalculationsAll calculations via the ZPL force an update to both the GUI and the core code. Pushing data to t
Hello!Long time fan of, and short time developer using the Raytrace.dll for fast batch ray traces in sequential mode. I have not tested it yet, but was wondering if the BatchRayTrace ray data returned accurate ray data for sequential systems that employ a non-sequential component? The application that I am thinking of is for a non-sequential group with a single segmented mirror, and it is convenient to set up the segmentation in a non-sequential group to alter individual mirror segment positions without using a very large number of multi-configurations. Thanks!Jaren
This forum post is a place to collect update history of diffractive tools beta functions, which includes all RCWA DLLs (and visualization API), polygon DLL, and Zemax Grating Data (ZGD) DLL. Content:1. Overview2. Resources3. Change history OverviewCurrently in OpticStudio, we are adding some useful DLLs to enhance the ability of fully simualting gratings. They allow OpticStudio to consider the efficiency when rays pass through diffractive optical elements (DOE), such like 1D/2D gratings, binary optics, or volume holograms. These extensions can be found in OpticStudio installations.These tools improve frequently based on users’ feedback. We decide to provide functions with DLL so it can be updaetd fast upon users' request. Between each OpticStudio public releases, there might be several minor updates and bug fixes. This forum post is a place for changes history.Note all tools provided here are only available with OpticStudio Premium Subscription. If users are interested in these functio
I am running dozens of non-sequential ray traces in a row, and I'd like to know of any tips for optimizing speed. My current process: Calculate a path for a moving source/detector. For each point in the path, move the source/detector a few mm (currently either a rectangle or STL detector) and run a ray trace. Aggregate the results at the end. I saw that you were considering using GPUs (in particular RTX cards) for ray tracing. Any progress on that? ETA? Maybe a beta build of OpticStudio that I can use? It would take a while to run 56 traces at 500k rays each on an 8k triangle STL. 🙂 Maybe I'm missing a simple way that this can be 10x faster.
Hi, In the ZOSAPI, the settings for the Physical Optics Propagation analysis feature are now fully implemented: So as an example, we may set the settings in the 'General' and 'Beam Definition' tabs using the ZOSAPI in MATLAB: TheSystem = TheApplication.PrimarySystem; TheAnalyses = TheSystem.Analyses; newPOP = TheAnalyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.PhysicalOpticsPropagation); newPOP.HasAnalysisSpecificSettings; newPOP_Settings = newPOP.Settings(); newPOP_Settings.Wavelength.SetWavelengthNumber(1); newPOP_Settings.Field.SetFieldNumber(1); newPOP_Settings.StartSurface.SetSurfaceNumber(1); newPOP_Settings.EndSurface.SetSurfaceNumber(4); newPOP_Settings.SurfaceToBeam = 0.0; newPOP_Settings.UsePolarization = true; newPOP_Settings.SeparateXY = false; newPOP_Settings.UseDiskStorage = false; newPOP_Settings.BeamType = ZOSAPI.Analysis.PhysicalOptics.POPBeamTypes.GaussianWaist; newPOP_Settings.XSampling = ZOSAPI.Analysis.SampleSizes.S_128x128; newPOP
I am trying to take a known set of Fringe Zernike Coefficients, and insert them into a zemax optical system model as a Zernike Fringe Phase surface. I’ve gotten as far as being able to insert the surface and set it as a Zernike Fringe Phase type, but I haven’t had any success with entering coefficient values into the LDE. I’ve tried LDE.GetSurfaceAt(28).GetCellAt(14).DoubleValue = valuewhere value is a float, but it throws an exception saying that a Double was expected and it got a string. I’ve also tried to just return a value that I’ve typed in manually, but had no success that way either. Can anyone point me in the right direction here? It seems like it should be simple with entering numbers into the LDE, but nothing has seemed to work so far. Thanks
This Source DLL models an Astigmatic Gaussian Source. It is based on rays but the statistical distribution of rays gives a picture of a diffracting Gaussian beam. It is valid for small angles (paraxial approximation) and when propagating in free space. So clipping at apertures and aberrations will give incorrect results.w0x, w0y are the real beam waist radii (defined at the 1/e2 intensity point) in the XZ and YZ planes. They includes M^2. z0x, z0y are the positions of the beam waist in the XZ and YZ planes. z0<0: in propagation direction if the waist is located before source. M^2x, M^2y are the quality factors in the XZ and YZ planes.For more information, see "Representation of a Gaussian beam by rays" by P. P. Crooker, W. B. Colson, and J. Blau - Physics Department, Naval Postgraduate School, Monterey, California 93943Authors:Steffen Erhard and @Dirk Broemme Download
The attached ZPL will calculate the air space gaps between all elements and then will place the annotation text on the Windows clipboard. After you run the script, simply open the Edit Annotation window, paste the text and click the Use Annotations checkbox: For the Double Gauss 28 degree field.zmx, the 3D Layout will look like:and for the Cooke 40 degree field.zmx: Limitations:You have to use the 3D Layout and not the 2d Layout. The 3D Layout uses global coordinates for annotations while the Layout uses “window” units, meaning the values for LINE and TEXT would change based on the current zoom position. For complete control, you should use LINE3D and TEXT3D (this would allow you to place things like Comment, Radius, or Material on the plot as well. For this simple example of air spaces, we will use MEASURE3D which is slightly easier to implement. Since we're only looking at air spaces, you need to consider when you “enter” a cemented element (doublet, triplet, etc) and when you “ex
This Mathematica code reads and writes binary .ZBF files, for use in Physical Optics Propagation (POP). We generate data for a Gaussian beam, write the data to a .ZBF file, and read the .ZBF file back in. Users can use this code to create their own beams to launch in POP. Users may also modify this code if they have beam data that they've measured in the lab, and want to launch the measured beam in POP. For more details, see the ReadWriteZBFs_12.PDF file included in the .ZIP file at the link below.Functions contained in the .nb file include: beaminfotable - Displays a table of important values for defining a Guassian beam. generategaussiandata - Creates beam data for a Guassian beam. WriteZBF - Writes a binary ZBF file. ReadZBF - Reads a binary ZBF file. findamplitueandphase - Converts the real and imaginary arrays in the ZBF file into amplitude and phase.Download
So my problem is roughly that I want to do my own tolerance analysis and retrieve the RMS Spot Radius value as my criterion. But after changing certain values, as the Thickness and Tilt X, the programme does not seem to register this. The Value is not changing and i just get the same value over and over again. Can someone explain how to effectively change these parameters in Optic Studio, so I can retrieve the actual RMS Spot Radius Value?I’m just assigning these parameters to my own values (f.e. from -10 to 10 with step 0.2) in a loop. Here a snippet of it:surf36 = TheSystem.LDE.GetSurfaceAt(36)mir1_thickness = surf36.ThicknessCell.DoubleValuemir1_tiltX = surf36.GetCellAt(14).DoubleValuefor indexTilt, stepTilt in enumerate(np.arange(-10, 10, 5)): mir1_tiltX = round(stepTilt, 2) spotdata_analysis = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.StandardSpot) spot_settings = spotdata_analysis.GetSettings() spot_settings.Wavelength.SetWavelengthNumber(0) spotd
Attached is a user-defined surface DLL that functions as an ideal thin lens obeying the Abbe sine condition. It is distinctly different than a paraxial lens surface and is particularly well-suited for simulation of high-NA objectives. The Ideal Lens surface requires two user-supplied parameters, namely the effective focal length and the paraxial magnification at which the lens yields optimal performance. It supports arbitrary conjugates (i.e., finite conjugate, or infinite conjugate in either object or image space) and is designed to work in both standard space and mirror space. A detailed description is provided in the included summary document, along with a discussion of several examples. The source code is not provided for now, but any and all feedback regarding the DLL functionality would be appreciated. Changes can be made accordingly.Here is a related link: Regards,Jeff
Hi Zemax Community, I have a quick question, is there a command for deleting all solves in the lens file using ZPL? I wasn’t able to find any resources. Would appreciate if someone can point me to the right resources or let me know what command I should use. Thanks![Mod note: moved to more appropriate forum for ZPL-related discussions.]
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
I’m working on a code to see how the Strehl ratio of our system changes over different iterations. I’m trying to extract the Strehl Ratio from the Huygens PSF like in the image below However, I can’t seem to find how I can do this. Can anyone help?
For the User defined object DLL, Zemax passes a variable “data” to the function UserObjectDefinition. However, I have not been able to find any documentation on what each element of this array is. The examples provide some of the parameters (for example the CoatingSample.dll file gives the first 15 parameters and a few others up to parameter 34, see the code below from the example). Where can I find documentation to understand what other parameters I have access to from this data structure? The data ZEMAX sends is formatted as follows: data, data, data = x, y, z data, data, data = l, m, n data = coat group number data, data, data = normal nx, ny, nz data, data = current and next index of refraction data = cosine of normal incidence angle data = wavelength in µm data = zero flag. Set this to 1.0 to indicate the DLL computes the coating data, otherwise, ZEMAX will compute u
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.