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
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 ?
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
We recently released ZOSPy 1.0.0, our open source library for easy communication between Python and OpticStudio. It uses the ZOS-API, but takes care of most of the programming, such as establishing the communication with OpticStudio and running and parsing analyses.The main new features included in this version are:Support for Python.NET 3.0 A uniform and pythonic interface to analyses:from zp.analyses.mtf import fft_through_focus_mtf mtf = fft_through_focus_mtf(oss, sampling='64x64', deltafocus=0.1) Autocomplete for the complete ZOS-APIAnd much more, see the release notes Check out the new version on GitHub.
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
Hello,I am having some difficulty finding answers on this elsewhere online and have not found any helpful forum posts on this either so here I am. I am trying to communicate with the POP with the python ZOSAPI with the program in interactive mode. Currently I have tried this little code snippit to set the surface desired to 2 and pull the irradiance with not much luck. Python more or less yells at me with an error saying “IAS_ object has no attribute ‘EndSurface’ I am not having the best of luck finding a solution to this problem in the help document. Please Help! :)FYI: See code snippit below # initialize analysis toolsTheAnalyses = TheSystem.AnalysesPOP = TheAnalyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.PhysicalOpticsPropagation)POP_set = POP.GetSettings()POP_set.DataType = ZOSAPI.Analysis.PhysicalOptics.POPDataTypes.IrradiancePOP_set.EndSurface.SetSurfaceNumber(2)POP.ApplyAndWaitForCompletion()POP_result = POP.GetResults()Irr = float(POP_result.DataGrids(1).Values) Cheers,Armand
Hello! A feature request -- could you please complete the ZPL API for geometric image analysis? It would be handy to be able to modify parameters available in the GUI that aren’t included in the API yet like the “use polarization” check box & the reference dropdown menu. Thanks!Liz
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,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
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
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
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?
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.