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.
Modifying Flux vs Wavelength settings with ZOS-API
Hi,I’m trying to obtain data from the ‘Flux vs Wavelength’ analysis tool while interacting through the ZOS-API (MATLAB). Setting a desired detector and wavelength bins then saving text output of flux by wavelength bin on that detector is my goal. There doesn't seem to be any direct way to modify these settings through the ZOS API, I have checked with the ‘HasAnalysisSpecificSettingsTool’. So I am trying to use the ‘ModifySettings’ route to change the configuration file (string code FVW). However, I cannot find the type codes for Flux vs Wavelength in the OpticStudio Manual or on any other help or discussion areas! I can do everything I required through the GUI, but not through ZOS API, which I am using to automate analysis. This is proving to be a large roadblock for our work.Could someone please let me know if what I am wanting to perform is possible and what the type codes for the Flux vs Wavelength analysis are?Or even better if there is a direct method to modify the settings throu
API (CS User Analysis): Non-Sequential Segment By Segment Path Analysis
This Zemax user analysis performs a path-analysis on an input ZRD file. The specified ZRD file will be read, and the ray paths sorted by total power in each path. This ray path analysis includes the hit-face data, meaning a ray which ghosts within a single object will be differentiated with the ray path which doesn’t ghost. This makes the analysis more robust than the native Path Analysis feature, but produces a more complex data output. As it is also slower than the native Path Analysis feature, it is recommended for use only when this level of detail is required in path analysis data. Some options are included to limit the depth of analysis to improve speed.Author: @Zach Derocher Click here to download Date Version OpticStudio Version Comment 2020/01/01 1.0 19.4 Creation
Python Zemax to SPEOS BSDF converter: version in progress
This example is a Python script to convert Zemax BSDF to Speos BSDF. The script is available here. It is not yet in the main branch as we are still running some tests but do feel free to use it and leave a comment.https://github.com/ansys/optical-automation/blob/BSDF-converter/ansys_optical_automation/application/BSDF_converter_example.pyThe user inputs are:BSDF_inputFilepath: the Zemax BSDF. A window will appear to select the BSDF. precisionTheta: the precision between theta values for the Speos BSDF. The default value is 1 degree. precisionPhi: the precision between phi values for the Speos BSDF. The default value is 1 degree.The script will create a Speos BSDF file in the same folder as the Zemax BSDF file. For more information about Ansys optical_automation, click here.
ZPL Macro: Sequential Jones matrix at each surface
This macro traces a single ray through the system. The Jones matrix is calculated at each surface. The Jones matrix is based on a plan normal to the traced ray. The electric field value after each surface can be calculated by multiplying the electric field before the surface by the Jones matrix. In the macro, the result from Polarization Ray Trace (POLTRACE) is also shown for comparison.Language: ZPL Click here to download Date Version OpticStudio Version Comment 2019/10/18 1.0 19.4SP2 Creation
How to use RCWA DLL to simulate rectangular amplitude grating
How do I simulate a rectangular amplitude grating using the RCWA DLL. I used srg_trapezoid_RCWA.dll for the simulation. I set Index Grate to 1, Index Env to 0.7-7.0i to simulate transmissive and opaque slits, and both substrate and outside refractive index are set to 1. However, I found that the diffraction efficiency calculated by it is quite different from that calculated by using scalar theory in the paraxial region. Also, when I change Index Env (e.g., 0.7-20i) and Depth, the diffraction efficiency changes more significantly. How can I simulate a rectangular amplitude grating that is consistent with scalar theory?
How to save detector viewer graphical plot into image file by ZOS-API ?
Hello, I would like to save graphical plot in detector viewer into a picture file by ZOS-API.I looked at some similar questions in community but most of those tell that “get numerical data and draw a plot using the numerical data” or “that feature is in request” 1 year go.So, I am wondering if that feature is implemented already or not.To me, GUI already has that feature and hence it seems that if there is a function in ZOS-API to call that feature in GUI, it gets the job done. Does anybody know that? RegardsKazu
MODIFTSETTINGS type codes for geometric MTF
Type codes for modifysettings are listed in the Zemax help files under: The Programming Tab > About the ZPL > KEYWORDS (about the zpl) > MODIFYSETTINGS (keywords) However, Geometric MTF is not listed here. My question is: what are the type codes for the geometric MTF analysis window?In case these do not exist, how would I go about modifying the settings for the geometric MTF analysis window via ZOSAPI?
Getting the Clear Aperture values from the surface names using a ZPL macro
Hello! I am new to ZPL Programming. I currently have the task to extract clear aperture values from Zemax (not according to surface number but the surface names ) using a ZPL macro. I am currently struggling to find the right command. It would be great if someone could help. Kind Regards,Santhoshi
Geometric ESF vs FFT ESF
In otpicstudion I am using, there are two way to get edge spread function. One is gemetric ESF, and the other is FFT ESF. I guess that FFT ESF are based on FFT, but don't know how the geometric ESF is calculated. Is it based on raytrace method rather than wave property of light?
writing ZRD2MAT files
Hey everyone. I have a NSC model that contains two sets of CPC’s and a Mersenne relay. My source is an array of conical wavefronts to mimic Cerenkov radiation. I need to trace a lot of rays through the system to the detector to look at the temporal dispersion of rays vs. time (or more correctly, Power vs. Time). So I’m writing my ray trace to a ZDR file. But when I convert it to text, I can’t get all the rays because the file is too large.So I want to try using the ZRD2MAT function that writes the ZRD data to a Matlab.m file.I have no idea how to do this. Currently, I’ve been creating a lot of text files with the ZRD info in them and reading and summing all the Optical Path data to get the total OP from source to detector. then, catching the last Intensity value for that ray and storing the info in a 2D array in Mathematica. It’s a PITA! I’d rather do it in Matlab.What path do I use if Matlab is in one folder and the lens is in another folder?anyone who can help me will get 100 Atta-Bo
How do I reload all surfaces by using Matlab API?
I notice these are “Reload Surface” and “Reload All Surfaces” tools on the top of the LDE window. Does anyone know how do we access this tool in Matlab API? I did not find such a function in ZOS-API. One similar function is “Reload Object” but it doesn’t work for “Reload Surface”.The reason why I need this function is I am simulating gradient index lenses whose property is read from an external file named “GRADIENT_9.DAT”. After I change the material property in this external “.DAT” file, I need to Reload All Surfaces to update the material.If anyone has suggestions on how to do this, I would appreciate it a lot.
import zosapi crashes jupyter kernel, how can I fix it?
Hello!I’m attempting to use the ZOS-API in Python (3.8.13). I’ve been running my code from the terminal window and have successfully executed a batch ray trace. I’m working on something that could benefit from using an interactive environment, so I am trying to use a Jupyter notebook or interactive cells in VS code.When I try to run <import zosapi> the kernel dies immediately. One of the errors thrown is“Unhandled Exeption: System.IO.FileNotFoundException: Could not load file or assembly ‘ZOSAPI_Interfaces, Version=220.127.116.11, Culture=Neutral, PublicKeyToken=null’ or one of its dependencies. The system cannot find the file specified”Am I missing a ZOSAPI_Interfaces file? Has anyone encountered this error before?Thanks,Jaren
Unable to connect Python (Spyder) to Zemax
Hi , I am currently trying to use python (Spyder) to connect with Zemax. But I am getting the errors below (shown in the picture below) . I can’t find any solution. I tried to use another python version - 3.7.0 , but still same error. Both standalone application and interactive extension result in same error messages. Appreciate if anyone could give me some guidance. Thank you
Ray trace settings using ZOS API in python
Hi all,I have been using ZOS-API Pythonnet to perform a ray trace and save the ray trace data as text files. The following program snippet worked perfectly fine up until a few months ago. Now, when I run the same code, it does the ray trace and saves the text file without changing any of the settings.import ZOSAPI;TheSystem = TheApplication.PrimarySystem;teleFile=('T_file.zmx')TheSystem.LoadFile(teleFile,False);Systemdata=TheSystem.SystemDataTheAnalyses=TheSystem.Analyses;X, Y = np.round(np.mgrid[(-1):(1):100j, (-1):(1):100j],3)positions = np.vstack([X.ravel(), Y.ravel()])pos=np.transpose(positions)px=pos[:,0]py=pos[:,1]max_rays=len(px)newWin=TheAnalyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.RayTrace);newWin_Settings=newWin.GetSettings();Field_1 = Systemdata.Fields.GetField(1)Field_1.X=0Field_1.Y=0path='\RT_trial'for i in range(max_rays): newWin_Settings.Px=px[i]; newWin_Settings.Py=py[i]; #newWin_Settings.Wavelength.SetWavelengthNumber(1); #newWin_Settings.Field.SetFiel
OPEV / OPEW
Hi,I would like to know how to use the OCOD and OPEV operands with multi configuration files: In case the same operand is present more than once (for example for different configurations) how to read the right one?Also, I want to know if it is possible to use OCOD with mathematical operands, like MINN, or MAXX, and same question, what if there is more than one in the Merit Function?Otherwise, is there a simpler way to read one value from any line in the MF?Thanks, Cristina.
Access coating properties in ZOS-API?
Is there a way to access the properties of a coating in the ZOS-API? The article below shows how to access the name of the coating, but does not show how to get the properties of the coating.I’m not finding any handles that give the actual coating information. Thanks!
ZPL Solve: Diffraction grating Littrow angle solve
Just a very simple ZPL solve to set the incident angle of a transmissive diffraction grating to the Littrow angle for order m = -1. #Define pipi = 2*ACOS(0)x = SOSO(0) #get preceeding coord break surface numberL = WAVL(PWAV()) #get primary wavelengthG = PARM(1,x+1) #return Lines/um from grating (pg 319)Litt = asin(L*G/2)*180/pi #Calculate Littrow anglesolvereturn Litt Just thought I’d share it to potentially save others a little time.It could be expanded for additional orders.
Mie scattering from a single water droplet
Greetings,I am attempting to model mie scattering for a single water droplet illuminated by a laser beam (monochromatic, collimated, and planar) and see the 'rings' on the detector varying with particle size. There is already a similar post: but no solution was reached.My current setup features a 'source ellipse' as the light source and a single 'Sphere' object as the water droplet with DLL Defined Scattering enabled under the Volume Physics tab. This much I have learned from the Zemax knowledgebase article entitled 'How to simulate atmospheric scattering using a Mie model'. My question now is what values for density and mean path should I enter in the MIE.DLL section under the Volume Physics tab?Suppose I start with a 10 micron diameter water droplet and I place the detector 500um (0.5mm) away from it, what density and mean path values correspond? Or is there a better approach?Thank you in advance.
Call a parameter by its name in the ZOS-API
When dealing with non-Standard surface types, you typically have access to extra parameters that are specific to that surface. For example, the Coordinate Break surface provides inputs for Decenter X, Decenter Y, etc. Coordinate Break surface type with the extra data parameters highlightedTo access these parameters in the API, our sample code offers two options:Access a parameter based on the parameter number. A typical command for this may look like the following: decenterX = TheSystem.LDE.GetSurfaceAt(1).GetSurfaceCell(ZOSAPI.Editors.LDE.SurfaceColumn.Par1).DoubleValue; Access a parameter based on its column number. A typical command for this may look like the following: decenterX = TheSystem.LDE.GetSurfaceAt(1).GetCellAt(12).DoubleValue;In both of these cases, you will need to have prior knowledge of the location in the LDE of the parameters you want to change. Or you will need to query the “Header” of the column you’re working with to confirm the parameter is correct. There is a th
CodeV to Zemax conversion
Error in converting from CodeV file to Zemax. Maximum length for a string variable is exceeded. Please shorten string and try again SEQ Command: VUX 0.2862643455614489e-9 -0.002507618428442271 -0.01007430775580165 -0.02275146039691922 -0.04038529897597765 -0.06242137400922543 -0.08826487454143517 -0.1181757056085635 -0.1349076575530941 -0.152878222887056 -0.1719304103266932 -0.1914365142446497 -0.2096016968531782 -0.2187861418214183 -0.2257120003786426 How to debug this. Please let me know
Already have an account? Login
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.