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.
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?
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
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
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?
The download contains 3 Python scripts:a script to read / parse a ZRD (Zemax Ray Database) file a script to read / parse a Binary ZBF (Zemax Beam File) file a script to read / parse a Binary DAT / SDF Source File Click here to download Date Version OpticStudio Version Comment 2022/01/01 1.0 - Creation
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
We have created a public repository called https://github.com/ansys/optical-automation. We are hoping to gradually move our solutions to this Ansys open project on GitHub.How to use Ansys optical-automationAnsys optical-automation comes with a documentation: https://ansys-internal.github.io/optical-automation/This section shows how to clone the GitHub repository and run the code in Visual Studio. Note the Visual Studio is not absolutely required. Users can use their preferred tool to sync the GIT repository and preferred IDE tool to run the Python project. Here we simply use Visual Studio as an example. Visual Studio installationUsers can download and install the latest Visual Studio in the following link: https://visualstudio.microsoft.com/vs/community/During the installation, the Python development must be selected as below.GitHub repository configurationAfter the installation, we can launch the Visual Studio and click Clone a repository.Copy and paste the link below to the Repositor
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?
Within the API, we are able to quickly pull Peak Irradiance, Total Power, and Total Hits by using the property GetDetectorData as described in the forum post 'Methods for extracting detector data through the API.' However, this property will not take into account an applied ZRD file. We can apply a ZRD file to a Detector Viewer window, so is there a way to extract the same information from there?
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?
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.