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 Source DLL models an Hermite-Gaussian Source using ray generated at position and angles following the intensity of the electric field and the angular spectrum. This Source DLL is inspired by the known DLL (Source): Non-sequential Astigmatic Gaussian DLL (Source): Hermite-Gauss take 4 parameters:w0_x, w0_y are the theoretical beam waist of the fundamental mode n_x, m_y are the mode indices in the corresponding directionsAuthors:Oran Meir - TriEye@Eyal Hollander- TriEye References:1. Goodman, J. W. (1996, January 1). Introduction to Fourier Optics. McGraw-Hill Science, Engineering & Mathematics, Ch 3.102. Carter, W. H. (1980, April 1). Spot size and divergence for Hermite Gaussian beams of any order. Applied Optics, 19(7), 1027. https://doi.org/10.1364/ao.19.0010273. Gaussian beam. (2023, September 3). Wikipedia. https://en.wikipedia.org/wiki/Gaussian_beam4. Fourier transform. (2023, September 27). Wikipedia. https://en.wikipedia.org/wiki/Fourier_transform5. DLL (Source): Non-se
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
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. 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
Hello! Can somebody please help me figure out how to change the surface for geometric image analysis? I’d like it to default to the image surface. gia_run = TheSystem.Analyses.New_Analysis_SettingsFirst( ZOSAPI.Analysis.AnalysisIDM.GeometricImageAnalysis ) # make new analysis, but don't run itgia_settings = gia_run.GetSettings() # I was hoping for something like the following (this doesn't work though)gia_settings.Surface = ZOSAPI.Analysis.Settings.Surface.IAS_Surface.UseImageSurfaceThanks!Liz
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’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?
I was helping a colleague with ZPL the other day. He wanted to know how to set a field as a variable and then constrain it. Additionally, he wanted to do this through a ZPL.The first part is easy enough. My approach was to expose the field as a variable through the multi-configuration editor using “YFIE”, declaring the solve as “Variable” and then constraining it in the merit function editor with “MCOL”, “MCOG”, or “MCOV”.For the ZPL portion, I wrote a small script for him demonstrating how to assign a variable in the MCE with ZPL.CLOSEWINDOW ! INSERTMCO, 1 # insert a row into the mce.SETMCOPERAND 1, 0, "YFIE", 0 # changes the operand to "YFIE"SETMCOPERAND 1, 0, 1, 1 # assigns YFIE to field no. 1 SETMCOPERAND 1, 1, 15, 0 # changes the value of row 1 config 1 to 15SETMCOPERAND 1, 1, 1, 3 # changes the solve type to "V"BEEP This made me think that it would be useful if there were a way to record GUI interactions as lines in a ZPL. For example, I could turn on the propose
Hey, I’m very naïve to Zemax and ZOS-API. I just tried to find the setting and run the code, but I couldn’t see the results from the image simulation.I used the standalone application and here is my code. # load local variables ZOSAPI = zos.ZOSAPI TheApplication = zos.TheApplication TheSystem = zos.TheSystem # Insert Code Here file = "C:/2021/Zemax_Image_Simulation/test.zmx" cfg = "C:/2021/Zemax_Image_Simulation/test.CFG" TheSystem.LoadFile(file, False) TheImageSimulation = TheSystem.Analyses.New_ImageSimulation() analysisSettings = TheImageSimulation.GetSettings() analysisSettings.ModifySettings(cfg, 'ISM_INPUTFILE', "Text_100p_3x3_2_g1196x1279_dist.png") analysisSettings.ModifySettings(cfg, 'ISM_FIELDHEIGHT', '15') analysisSettings.ModifySettings(cfg, 'ISM_FLIPIMAGE', '3') analysisSettings.ModifySettings(cfg, 'ISM_OUTPUTFILE', 'Test1.png') analysisSettings.LoadFrom(cfg) a = TheImageSimulation.ApplyAndWaitForCompletion()
I am writing a program where I need to make several changes to values in the Lens Data Editor (e.g. parameters of a coordinate break surface) and evaluate merit function operands after each set of changes. The problem is this is extremely slow, to the point that setting the parameters dominates runtime far beyond the time spent raytracing. For example, this function averages about 1 second per call:def set_offset(oss, surface_number, x, y, about_x, about_y): oss.LDE.GetSurfaceAt(surface_number).SurfaceData.Decenter_X = x oss.LDE.GetSurfaceAt(surface_number).SurfaceData.Decenter_Y = y oss.LDE.GetSurfaceAt(surface_number).SurfaceData.TiltAbout_X = about_x oss.LDE.GetSurfaceAt(surface_number).SurfaceData.TiltAbout_Y = about_y I’m sure there are some minor optimizations I can make, but at its core, setting a single variable in memory shouldn’t take anywhere near 0.25 seconds.Am I doing something wildly wrong, or is there a far more efficient way to modify LDE entries? Is ther
Hi, currently we have different Network Licenses for Ansys Zemax OpticStudio and Legacy Zemax OpticStudio in our company. Depending on which license is free I’m using Ansys Zemax or Legacy Zemax. However, most of the time I am working with the ZOS Api in python.The problem is when I use the ZOS Api and all Ansys Licenses are currently used, the ZOS Api throws the LicenseException, although there are free Legacy Licenses (I am able to open Legacy OpticStudio). Is there a Workaround to tell the ZOSAPI to look for legacy Licenses as well?Thanks,Benjamin
Hi,I’m looking for “us_gskew.dll” shown to be used in “Using skew rays to model Gaussian beam propagation in OpticStudio” webinar.I download the attached zip files which contained *.c file. I wonder where can I find the complied file. is there a reasone why I couldn’t used an allready complied filed? (and instead have to complie it myself)Thank you,Amir
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 ?
Hi, I’m trying to develop a ZPL macro that can get the Through Focus Geometic MTF which modifysettings key word is “Tfg”. But I’m not able to find detail explanation of “Tfg” in UserManual.PDF. In case of “Tfm”, I know the Modifysettings of “Tfm” is supported. I was able to run the ZPL code like below. MODIFYSETTINGS tfmcfg$, TFM_SAMP, calc_tfm_sampBut the ZPL code include “Tfg” like below has errored.MODIFYSETTINGS tfgcfg$, TFG_SAMP, calc_tfg_sampERROR in MODIFYSETTINGS: Incorrect version number in settings file.Please let me know whether “Tfg” code is supported or not?Keiya Yoshida
Hello!I’m attempting to use the `zosapi` package with @MichaelH ‘s RayTrace.dll for fast batch ray tracing in Python. It works just fine when I call Python scripts from some terminal, but am having some difficulty using it in Jupyter/IPython notebooks.Below shows where the kernel crashes, without giving me a stack trace to try and diagnose why the kernel is crashing. Has anyone encountered this problem before?
The tool provided in this post is part of a workflow to simulate the CMOS sensor response. The workflow includes 3 steps. (1) Analyze chief and marginal rays information for the target lens data system in OpticStudio.(2) Calculate the conversion efficiency from incident optical power to output electric power in Lumerical.(3) Utilize the data of conversion efficiency and the irradiance from optical simulation in Speos to get the final electric power map. In this post, the tool for first step is introduced. By running this tool with a given lens system, we calculate and export the data of chief and marginal rays’ angle for different position on the image surface. For step 2 and step 3, the information will be updated soon in following two articles:CMOS Sensor Camera - Sensor Characterization – Ansys OpticsCMOS Sensor Camera - Image Quality Analysis in a 3D Scene – Ansys Optics The process in this step is as below.Open the lens system. Perform Design Lock Down tool in the Tolerance tab in
I’m writing a script to do a lot of automation and has a lot of inputs for different configurations. I’m trying to combine multiple .ZBF, each with a different field position. This means I need to use ZBFRESAMPLE to shift the images to match their offsets compared to the on-axis field. This is quite handy since I can use physical units to shift the image rather than try and figure out how many pixels I need to shift by.The only other option I can think of is to have the API run a macro, however, I think I would need to have the ability to have the API input variables into a macro which I don’t think is possible.Does anyone know if it’s possible to call just one ZPL function in API or do I need to figure out how to mix API and ZPL?
So I’m trying to optimize a design in Zemax non-sequential. However I’m noticing that there is a discrepancy between what the MF editor reports, and what I see from running ray trace and running detector viewer. My MF looks like the following: And I see that the total flux (line 7) is 0.619 out of .75. This is a very good number. So then I cancel the optimization, and perform a ray trace, and when I take a look at the detector viewer, I get the following:How can the MF editor be displaying 0.619, yet the total power, which I think is the same metric on the detector viewer is indicating 0.422?
Attached python script loads a ZBF and propagate the beam to a specific range with given sampling. And then draw the beam in YZ view.Currently POP doesn’t support YZ view, but we can first save a ZBF file and use this tool to show YZ for desired range in z direction.The settings are as below.The beam will be drawn for the range between d1 and d2. We can specify the sampling with the variable samp. The UseAngularSpectrumPropagator must be True for now. We could update it to support False, but this requires some more complicated stitching process. The wave should be correctly set up with the wavelength in the ZBF, otherwise we would get wrong result. Click here to download Date Version OpticStudio Version Comment 2023/08/14 1.0 23R2 Creation
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.