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.
Specifying a UDA file to a Surface Aperture as an Aperture file using Python
Hello Everyone,I am trying to change the Aperture file of a surface aperture using python. All I could do is to change the Aperture type to User Aperture but the Aperture file is not specifyed.This is the code I am usingfilename= ‘HP.uda’User_Aper =TheLDE.GetSurfaceAt(2).ApertureData.CreateApertureTypeSettings(ZOSAPI.Editors.LDE.SurfaceApertureTypes.UserAperture)User_Aper.ApertureFile = filenameSurface_3.ApertureData.ChangeApertureTypeSettings(User_Aper) Using Matlab, it is working perfectly using the same code and also, it works that I can change the Aperture file manually in zemax so this means the aperture uda file is at the correct location with the correct content.I also tried to change the filename string to the full directory of the uda file and it is not working too. [Mod note: moved to more appropriate forum for ZOS-API related discussions.]
Ideal Lens DLL (user-defined sequential surface satisfying the Abbe sine law)
Attached is a user-defined surface DLL that functions as an ideal thin lens obeying the Abbe sine condition. It is distinctly different than a paraxial lens surface and is particularly well-suited for simulation of high-NA objectives. The Ideal Lens surface requires two user-supplied parameters, namely the effective focal length and the paraxial magnification at which the lens yields optimal performance. It supports arbitrary conjugates (i.e., finite conjugate, or infinite conjugate in either object or image space) and is designed to work in both standard space and mirror space. A detailed description is provided in the included summary document, along with a discussion of several examples. The source code is not provided for now, but any and all feedback regarding the DLL functionality would be appreciated. Changes can be made accordingly.Here is a related link: Regards,Jeff
ZPL Operand: Extract FWHM from non-sequential detector
Description: This macro will calculate the approximate FWHM of a near-Normal distribution of data. This macro assumes symmetry about the maximum value and assumes a minimal amount of noise between 0 and the maximum. The macro will update the Detector Viewer settings to a cross-section view. Then, the data will be extracted and evaluated. When using the ZPL10 version of the macro, the approximate FWHM will be reported when Data = 0 for the X-direction, and Data = 1 for the Y-Direction. Use the Hx entry to specify the detector of interest. Language:ZPLUpdates:10/22/2021 - Stability and calculation updates. The calculation is now more robust. The code for finding the CFG file has been updated. See the ReadMe for more information. Download: Click here to download Date Version OpticStudio Version Comment 2019/10/15 1.0 19.4SP2 Creation 2020/10/14 2.0 20.3 Updated macro with the following - CFG file is programmatically calculated - FWHM index location calcul
OpticStudio grating tools beta function update history
This forum post is a place to collect update history of diffractive tools beta functions, which includes all RCWA DLLs (and visualization API), polygon DLL, and Zemax Grating Data (ZGD) DLL. Content:1. Overview2. Resources3. Change history OverviewCurrently in OpticStudio, we are adding some useful DLLs to enhance the ability of fully simualting gratings. They allow OpticStudio to consider the efficiency when rays pass through diffractive optical elements (DOE), such like 1D/2D gratings, binary optics, or volume holograms. These extensions can be found in OpticStudio installations.These tools improve frequently based on users’ feedback. We decide to provide functions with DLL so it can be updaetd fast upon users' request. Between each OpticStudio public releases, there might be several minor updates and bug fixes. This forum post is a place for changes history.Note all tools provided here are only available with OpticStudio Premium Subscription. If users are interested in these functio
Accessing filtered detector data with ZOSAPI
I would like to access, through ZOSAPI, detector data which has been fitered by a filter string. I know how to access detector data through ZOSPI. And it is of course possible to view filtered data in OpticStudio by saving a trace to a ZRD file and specifiying that as the database for a detector viewer. The filter string can be applied as the ZRD is saved, or applied in the settings of the detector viewer. But I would ike to access the filtered data as it is viewed in the detector viewer, rather than the unfiltered data. Is this possible? I am actually using ZOSAPI from Mathematica, but an answer related to Python or C++ would be useful. Kind regards, David,
Saving ray data ZRD to a file in a loop
Hello together,I’m trying to save Ray Database ZRD to a file in a loop for each angle in the following script:...for angle, -10, 10, 2 x = NSDD (1,0,0,0) SETNSCPOSITION 1,2,6,angle PATHRAY$ = "Rayfile_" + $Str(angle) + ".ZRD" NSTR 1,0,1,1,1,1,1,1,PATHRAY$,"h133",1 UPDATE ALL PAUSE THREADSNEXT This just a part of my script, and exactly this part, namely the saving of ray database is not working. How can I save it, so I could have a few Ray Database files for different angles and open it later with the Ray Database Viewer? What is wrong here?Thank you in advance!CheersMax.
STAR: Load FEA data with your command line
I put all the scripts and detailed documents in the zip file, “star_load_fea_cli.zip”. The script “main_cli.py” is a command line tool that I use to import the FEA data to the system via the STAR module. The feature is almost the same as the “Load FEA Data” tool in the STAR module. The difference is that this tool cannot help you check whether the FEA data is in the right place. However, it might be able to help you finish some routine work. If the script is not convenient enough to let you finish your work easier and you want to build your own tool, I think you can reference the functions “load_fea_deformation_with_transform” and “load_fea_temperature_with_transform”. I believe that they will give you some help.
Performing DOE with tilt and decenter while extracting image simulation results
Hello Everyone, I want to run a DOE with ZEMAX where the idea is to generate synthetic data by running image simulations while changing position of lenses (adding decenter and tilt to individual lens elements in a lens stack).I want have a bunch of tilt and decenter scenarios and would like to automate the process via API.Is there a sample code that I could use for this application? Is there a sample code to automate image simulations and save resulting images in general that I could modify to suit my needs?All suggestions are appreciated :) Best regards,Amit
Saving an image from Geometric Bitmap Image Analysis for different configuration
Hello, I would like to use a macro to save images from Geometric Bitmap Image Analysis for different configuration.I wrote this macro in ZPL to save the images obtained for different configurations but it doesn’t work:! Read the # of configsNCONFIG = NCON()!Read pathsettingfiles$ = "...\Zemax\Configs\IMB.CFG"! Execute for each configFOR i, 1, NCONFIG, 1 ! Set config SETCONFIG i img_file$ = $STR(i) + ".png" MODIFYSETTINGS settingfiles$, GBM_OUTPUT, img_file$ OPENANALYSISWINDOW "IBM" PAUSE THREADS NEXTPRINT "DONE!"The configuration changes and the Geometric Bitmap Image Analysis window opens up and displays the right image but nothing is saved. Moreover, the output file name keeps the initial name and it isn’t modifying for each configuration. Do you have any idea to save those images ? (the folder path doesn’t matter) I also wrote another ZPL macro which works and saves the image of the opened window following the different configuration but it still not really what
How to modify Settings of Geometric Bitmap Image Analysis?
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.
A question about create automatically optimization wizard table by ZPL
HiI'm trying coding a ZPL script to create an automatic optimization wizard table.My target optimization wizard table was show as below picture. Here is producing optimization wizard table by running my ZPL script.Unfortunately, they have three differences by comparing the two created optimization wizard tables and making numbers on the above pictures. Here is a list of the parameter value for differences. This is show the partial screenshot of my ZPL script, the code also attached to set Merit Function.zip. What kind the command settings/paraments were missing in this ZPL script? That can be fixed for the three differences.
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
Problem with rotation matrix article
https://support.zemax.com/hc/en-us/articles/1500005576822-Rotation-Matrix-and-Tilt-About-X-Y-Z-in-OpticStudio is misleading.OpticStudio uses degrees for Tilt About X/Y/Z, and this graphic suggests using theta_x = tilt about x. Tilt about X is in degrees, but theta_x should be in radians. If you do as the graphic suggests and plug in degrees, you'll get the wrong rotation matrix.Please let me know if I'm wrong here.
Python Converting an image into a ZBF file
This Python converter reads an image file and converts it into a ZBF file. The image is used for the amplitude of the electric fields. The phase of the electric fields is set to zero. Note that the conversion may not work properly for color images depending on the color scheme. Convert your image to a grey scale before the conversion Click here to download Date Version OpticStudio Version Comment 2022/11/02 1.0 - Creation
Path Analysis Loss of Power and Atmospheric (Air) Losses
Hi,I’m using the Path Analysis feature (run from Matlab) to analyze how the light is going through a system. Path Analysis is a great feature!What I’m noticing is that if I add up the number of rays in the path analysis rows, they equal to the number of rays in the ray trace / and in the layout. However, if I add up the powers in the rows, there is a total loss of about 1.8%. I currently do not have any coatings set on the various components (struggling to get that to work for some unknown reason or the other). Just mirror/reflector and absorbers.Is there an atmospheric loss built into Zemax due to the air the light passes through? I tried setting the air pressure to zero in the System Explorer/Environment to try and simulate a vacuum, and it didn’t change anything. And, if there are air losses, I’d like to control them or set them to zero and calculate the losses numerically. Thanks!
Simulating PTFE Integrating Sphere
Hello,I’m trying to simulate a PTFE Integrating Sphere using the predefined macro that we can find in sample files ...\Zemax\Samples\Non-sequentional\Miscellaneous\Integrating Sphere.zmxI was able to change dimension of sphere and port but im finding the following problem:1. How can I change the material MIRROR in PTFE?2. Can I inserti a material inside the sphere?3. How Can I calculate the number of refraction inside the sphere and the number of photons that reach the detector?4. How Can I simulate the Homogeity inside the Sphere?5. The detector viewer doesnt work, how me always the same results….Why?A guide about simulating an integrating sphere can help me so much...Thanks for the support.The code is as attachments.Best Regards.
Quicker way to set parameters in the LDE
Hi,I am using the ZOS-API interface with Python (pythonnet 2.5.2.) to set the coefficients for a Zernike Standard Sag surface, one at a time. It takes several seconds!! Is there any faster way, or a way to set all parameters at once?I’d like to run a Monte Carlo analysis with thousands of istances of zernike surfaces, so a faster way would be really beneficial.%timeit M1_surf.GetCellAt(30).DoubleValue = 6.46449601150208e-06386 ms ± 28.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)%timeit M1_surf.SurfaceData.SetNthZernikeCoefficient(4, 6.46449601150208e-06)354 ms ± 27.5 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) As a comparison, reading a value is three orders of magnitude faster:%timeit M1_surf.GetCellAt(30).DoubleValue513 µs ± 78.3 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each) The LDE is the only open window, so there are no analyses being updated. Any help would be very much appreciated! Paolo
GetTextFile returns True, but does not create a file in ZOS-API via Python
Hi, Having started with the default python Interactive Extension template generated by OpticStudio, I added the following code:# Insert Code Herehuygens_psf = TheSystem.Analyses.New_HuygensPsf()huygens_psf.ApplyAndWaitForCompletion()success = huygens_psf.GetResults().GetTextFile("textdump.txt")print(success)When running this as an interactive extension, the following gets printed to my terminal emulator:Found OpticStudio at: %sc:\program files\zemax opticstudio Connected to OpticStudio Serial #: L118546
How to retrieve RMS Spot Radius Value after changing certain parameters (Thickness, TiltX)?
So my problem is roughly that I want to do my own tolerance analysis and retrieve the RMS Spot Radius value as my criterion. But after changing certain values, as the Thickness and Tilt X, the programme does not seem to register this. The Value is not changing and i just get the same value over and over again. Can someone explain how to effectively change these parameters in Optic Studio, so I can retrieve the actual RMS Spot Radius Value?I’m just assigning these parameters to my own values (f.e. from -10 to 10 with step 0.2) in a loop. Here a snippet of it:surf36 = TheSystem.LDE.GetSurfaceAt(36)mir1_thickness = surf36.ThicknessCell.DoubleValuemir1_tiltX = surf36.GetCellAt(14).DoubleValuefor indexTilt, stepTilt in enumerate(np.arange(-10, 10, 5)): mir1_tiltX = round(stepTilt, 2) spotdata_analysis = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.StandardSpot) spot_settings = spotdata_analysis.GetSettings() spot_settings.Wavelength.SetWavelengthNumber(0) spotd
Python fit object face (ex. for CAD)
Attached file shows alternative method to the following code.ZPL Macro：Fit CAD surface as a sequential surface It uses ZOS-API with Python. The benefit is we will generate the fitting system automatically. A document is provided to show a simple example about how to use it.
ZOS-API can not set analysis window correctly
Hello Everyone,I want to use python standardalone to open a analyse window of huuygens PSF ,but i find that doesn’t work. althought the windows is opened, but settings has not been set correctly. the code like this, I want to set SampleSize as 64 ,but when I open the file, that still the default setting of 128:TheAnalyses = TheSystem.AnalysesnewWin = TheAnalyses.New_HuygensPsf()print("HuygensPsf has analysis specific settings? ", newWin.HasAnalysisSpecificSettings) newWin_setting = newWin.GetSettings()newWin_setting.PupilSampleSize = ZOSAPI.Analysis.SampleSizes.S_64x64 print(ZOSAPI.Analysis.SampleSizes.S_64x64)newWin_setting.ImageSampleSize = ZOSAPI.Analysis.SampleSizes.S_64x64 print(ZOSAPI.Analysis.SampleSizes.S_128x128)newWin_setting.HuygensPsfTypes = ZOSAPI.Analysis.Settings.HuygensPsfTypes.Phase newWin.ApplyAndWaitForCompletion() And i also get a problem about the warning of this, for I have already pip install pythonnet, and uninstall clr. it is still not worked.
Pythonnet 3.0 not recommended to use for ZOSAPI-Python
Pythonnet is a package that gives Python programmers an integration with the .NET Common Language Runtime (CLR).Our ZOS-API is a .NET 4.8-based library. So the Pythonnet version should support .NET 4.8 to be used with ZOS-API.We had some reports that pythonnet 3.0 didn’t work with ZOS-API. I also did a couple of tests last week and encountered issues. So the recommendation for now is not to use pythonnet 3.0 with ZOS-API.I personally use pythonnet 2.5.2.
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.