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.
Hi there, I am trying to write a source DLL file to use in OpticStudio, which is based on the built-in source “Source Two Angle”. It would be great if I could use this as a starting point. Is the (cpp) code available for this source? Or is there something similar I could start with? Thank you!
Hi!I am experiencing a bug when running local optimisations via the ZOS-API in python. I am using interactive extension. Example of the code is:LocalOpt = TheSystem.Tools.OpenLocalOptimization()LocalOpt.Algorithm = ZOSAPI.Tools.Optimization.OptimizationAlgorithm.DampedLeastSquaresLocalOpt.Cycles = ZOSAPI.Tools.Optimization.OptimizationCycles.Fixed_50_CyclesLocalOpt.NumberOfCores = 8LocalOpt.RunAndWaitForCompletion()LocalOpt.Close()Upon running this, it sometimes completes correctly, but sometimes the optics studio window crashes and closes. Then when i open it back up, it asks if i want to restore the file. I have also tried this on multiple machines with different installations of ZEMAX, and the same thing occurs: sometimes it completes the optimisation and sometimes it crashes. Has anyone else experienced this issue, or know a fix? Thanks very much in advance!!
Hello all,I am a student in internship and I need to use ZPL to automate my system. I have a system with LED, which I am optimizing. After this optimization I have to measure the power received on the detector for different Z positions (34 positions).I do not know how to make a list of my different Z positions, how to change the value of the Z position for my detector and how to retrieve the value of the power received on my detector.Thank you in advance,Léo
If you were part of the Code Exchange User Group, you may notice that it is no longer available. With our recent updates to the Code Exchange, we determined the group was no longer necessary and closed it. It has been merged with the broader forum category.Now, if you’re looking users’ submissions to the Code Exchange, you can find them all in the Code Exchange forum, regardless of login status. This forum will house a summary of each of the solutions. All users have access to this space. All of the Code Exchange download files have been moved to the Code Exchange Download Center. The download center and the files therein are restricted to supported users only. If you want to submit an item to the Code Exchange, you can do so directly in the forum. Create a topic in the Code Exchange forum using the tag Code Exchange - for review. Be sure to include a ReadMe doc or the submission will not be accepted. Once posted, our team will verify it and work with you to have it officially posted i
I am trying to view/export the zernike data of my system using Matlab and the API. Currently my code reads: And I don't know what to do from here. The data comes to Matlab in an IAR file type, and I don't know how to extract it. Thanks, Stephen Chapman
This diffractive DLL make the face behave like a Paraxial Lens which can correctly consider phase.Note the Paraxial Lens correctly gives phase information only when the object/image distances are correctly given. Therefore, the parameter “Image Position” should be explicitly given. If the image is formed at infinity, the parameter “Image Position” is set to 0. For the other conjugations, the image position is the distance between the image plane and the diffractive object along the local axis.There are a few limitations when using this diffractive DLL.(1) The ray must be from -z side and propagate to +z side.(2) Only the transmit rays are considered, the reflect related parameters can be set the same way as the included sample files.(3) Only order 0 are considered.(4) Refractive index at two sides must be AIR (n=1.0).To obtain the same layout, please check the ‘Split NSC Rays’ option in NSC 3D Layout.Please pay attention to the detector size and the PSF Mode Wavenumber when you change
I had a post in Chinese but maybe this helps more people who wants to simulate the tolerance of their systems using ZPL. 如何使用ZPL改变POP中的beam和fiber数据 | Zemax CommunityThe MODIFYSETTING can be applied on the .CFG which has the same name of your design file and locates under the same directory of your file. This is the file that the POPD reads. You have to manually click the SAVE button to generate this file first. If we modify the POP.CFG, it does not work.Here is the sample ZPL code.popCFG$ = "C:\Users\Desktop\Fiber Coupling.CFG"MODIFYSETTINGS popCFG$, POP_FPARAM1, 0.005MODIFYSETTINGS popCFG$, POP_FPARAM2, 0.005OPENANALYSISWINDOW POP, popCFG$PRINT MFCN()The OPENANALYSISWINDOW may not be necessary for certain users. When I run the test, I need this line to activate the modification on this CFG file.
I’m using ZOS-API by matlab.I’ve tried to run Geometric Bitmap Image Analysis and succeed Running Analysis by using Interactive Extension.GeoBitIA = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.GeometricBitmapImageAnalysis);I want to control some setting by using matlab. However I do not find right method to modify Settings.Do me a favor to do that things.Thank you.
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 Download
Hi Zemax community,I am a student who is learning to use the ZOS API in Matlab and I’m having issues with getting results from New_WavefrontMap. How do I correctly pull data from a wavefront map? As the results I plot are always zero.I am running a wavefront analysis and POP analysis in the same program, which uses the ‘Double Gauss 5 degree field.zmx’ file from samples. I apply the analysis then pull the results using the following code to get the data:WF_Map_Data = New_WF_map_results.DataGrids(1).Values.double;matrixData = POP_Results.DataGrids(1).Values.double;and try to plot it in Matlab the matrix will be populated by zeros.Wavefront map populated by 0’sBoth wavefront map and POP are set up in a similar fashion, but when plotting the results of the POP it will not be populated by zeros.POP resultThanks for readingNick
I am running tolerancing analysis (TA) using Matlab. I noticed that one tolerance data viewer window will show up after the TA is finished. I would like to close the viewer window using Matlab script however I was not able to find the right way to do it in ZOS-API manual. Do you know how to close the viewer window using Matlab script? Thank you very much.
Hi. I am using the ZOS-API for Python and try to switch to the new recommended method of using PythonNET instead of the COM interface. To do so, I created a new Python template using 'Programming>Python>Interactive Extension' (same problem occurs with 'Standalone Application'). Running this template fails when trying to add the NetHelper DLL: import clr, os, winreg from itertools import islice # determine the Zemax working directory aKey = winreg.OpenKey(winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER), r'Software\Zemax', 0, winreg.KEY_READ) zemaxData = winreg.QueryValueEx(aKey, 'ZemaxRoot') NetHelper = os.path.join(os.sep, zemaxData, r'ZOS-API\Libraries\ZOSAPI_NetHelper.dll') winreg.CloseKey(aKey) # add the NetHelper DLL for locating the OpticStudio install folder clr.AddReference(NetHelper) import ZOSAPI_NetHelper --------------------------------------------------------------------------- FileNotFoundException Traceback (most recent call
This macro reads the text output of the image simulation. The text output contains the RGB values of the image for each pixel. It then creates a cross section of the image simulation in X or Y for a defined X or Y pixel.In the Image Simulation window, click on Save first before running it.Download
Could anyone help troubleshoot an error when running the NSC RayTrace in Interactive Extension mode from Matlab - ‘Unrecognized field name "ClearDetectors".’?The code always runs the first time through, and then the second time through the below routine, either in the same program execution or after stopping and starting again, it hangs up on NSCRayTrace.ClearDetectors(0); % Ray Trace % Create ray trace NSCRayTrace = TheSystem.Tools.OpenNSCRayTrace(); NSCRayTrace.SplitNSCRays = false; NSCRayTrace.ScatterNSCRays = false; NSCRayTrace.UsePolarization = true; NSCRayTrace.IgnoreErrors = true; NSCRayTrace.SaveRays = false; NSCRayTrace.SavePaths = true; NSCRayTrace.SavePathsFile = 'Simulation_temp.PAF'; NSCRayTrace.ClearDetectors(
In OpticStudio, We can load any BSDF file from our \Zemax\ScatterData Folder .Here is the available code for Matlab and Python. You can use this code in Standalone or Interactive Extension.-Copy the code in your file .-Change the path of testfileMatlab Code: TheNCE = TheSystem.NCE; Object_2 = TheNCE.GetObjectAt(2); % changes scatter profile on face Scatter_Data=Object_2.CoatScatterData.GetFaceData(0);o3_Scatter = Scatter_Data.CreateScatterModelSettings(ZOSAPI.Editors.NCE.ObjectScatteringTypes.BSDF); o3_Scatter.S_BSDF_.ReflectFile = 'BrownVinyl.bsdf'; o3_Scatter.S_BSDF_.TransmitFile = 'BrownVinyl_HighRes.bsdf'; o3_Scatter.S_BSDF_.ScatterFraction = 0.775; o3_Scatter.S_BSDF_.Angle = 30; Object_2.CoatScatterData.GetFaceData(0).ChangeScatterModelSettings(o3_Scatter); Object_2.CoatScatterData.GetFaceData(0).NumberOfRays = 2; Python code :testFile = r"C:\test\Digital_projector_flys_eye_homogenizer.zos"TheSystem.LoadFile(testFile, False)print(TheSystem.SystemFile)TheNCE = TheSystem.
In OpticStudio, We can load any spectrum file from our \Objects\Sources\Spectrum Files Folder .Here is the available code for Matlab and Python. You can use this code in Standalone or Interactive Extension.-Copy the code in your file .-Change the path of testfileMatlab Code: import ZOSAPI.*;TheSystem = TheApplication.PrimarySystem;sampleDir = TheApplication.SamplesDir;testFile = System.String.Concat("C:\test\ZPO\Diode sample.ZMX"); NSCE = TheSystem.NCE;Obj1 = NSCE.GetObjectAt(1); Source_Color=Obj1.SourcesData.SourceColor;Source_Color=ZOSAPI.Editors.NCE.SourceColorMode.SpectrumFile;filesAvailable = Obj1.SourcesData.SourceColorSettings.GetAvailableSpectrumFiles();FileToSelect=filesAvailable(6);Obj1.SourcesData.SourceColorSettings.SpectrumFile=FileToSelect; Matlab Interactive Extension Python Code:testFile = r"C:\test\ZPO\Diode sample.ZMX"TheSystem.LoadFile(testFile, False)print(TheSystem.SystemFile)NSCE = TheSystem.NCEObj1 = NSCE.GetObjectAt(1) Source_Color=Obj1.SourcesData.Sourc
Hello, I am trying to use the ZOS-API through Python. I have found the knowledgebase articles to be very scattered and confusing. I would like to access the dictionary of enumeration constants referenced multiple times in the linked article. However, the article does not show how to find the constants dict within ZOS-API. And, the source script for the code snippets is not linked in the article attachments! Does anyone know how I can access the constants dict through python? Thanks in advance.https://support.zemax.com/hc/en-us/articles/1500005576662-ZOS-API-using-Python
In opticStudio ,we can set User defined surface through Python and Matlab program using standalone and Interactive Extension.-Set the user defined surface -Select the User defined surface from directory-Get the User defined surfaceMatlab Code:You can directly copy the code in Standalone or Interactive Extension: import ZOSAPI.*; % Set up primary optical system TheSystem = TheApplication.PrimarySystem; sampleDir = TheApplication.SamplesDir; testFile = System.String.Concat('C:\test\ABCD\ABCD Simple_lens.zmx'); TheSystem.LoadFile(testFile, false); TheLDE = TheSystem.LDE; surf2 = TheLDE.GetSurfaceAt(2); typeSettings = surf2.GetSurfaceTypeSettings(ZOSAPI.Editors.LDE.SurfaceType.UserDefined); filesAvailable = typeSettings.GetFileNames(); typeSettings.Filename = filesAvailable(5); surf2.ChangeType(typeSettings); d=typeSettings.Filename; disp(d) Interactive Extension Matlab Python Code:You can directly copy the code in Standalone or Interactive Extensi
Hello! I am trying to retrieve data about wavefront via ZOS-API in Matlab. Since I need to iterate through different positions of mirror, I am using coordinate breaks and iterate through them using arrays and FOR cycle:decenter = [-0.5:0.1:0.5];tilt = [-0.2:0.04:0.2];for i = 1:tilt_length for j = 1:decenter_length disp([i j]); TheSystem.LDE.GetSurfaceAt(3).GetCellAt(13).DoubleValue = decenter(j); % I set decenter here in the coordinate break (surface 3) TheSystem.LDE.GetSurfaceAt(3).GetCellAt(14).DoubleValue = tilt(i); % I set tilt here newWin = TheSystem.Analyses.New_WavefrontMap(); % Requesting new window newWin_Settings = newWin.GetSettings(); % Requesting settings newWin_Settings.Wavelength.SetWavelengthNumber(1); % Setting wavelength number newWin_Settings.Field.SetFieldNumber(1); % Setting field number newWin_Settings.Sampling = ZOSAPI.Analysis.SampleSizes.S_1024x1024; % Setting sampling newWin.ApplyAndWaitForCompletion(); % Applying the settings
I am able to control IntegerValue parameters of objects in ZEMAX from MathematicatheSystem@NCE@GetObjectAt@GetObjectCell[ObjectColumn`Par2]@IntegerValue = 512; however DoubleValue object returns an errortheSystem@NCE@GetObjectAt@GetObjectCell[ObjectColumn`Par6]@DoubleValue = 10.1; NET::netexcptn: A .NET exception occurred: System.ArgumentException: Expected Double, got 'String' at ZemaxUI.ZOSAPI.Editors.ZOSAPI_EditorCellBase.set_DoubleValue(Double value). What is the syntax to control a DoubleValue object? Thank and BR,Jozef
Can anyone point me to the tools/commands to call the Non-sequential Path Analysis Tools in ZOS-API? From Matlab, in Interactive Extension mode on a non-sequential object set, I’d like to be able to execute the path analysis to create the .PAF file and then import that .PAF file into Matlab or at least the desired parts of the .PAF file. I could then do some analysis on the individual aspects of the .PAF file. I’ve been looking in the documentation and not having much luck.Thanks!Josh
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.