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.
Change a detector position on Z-axis using SETNSCPOSITION
Suppose I have a source (surface 1) and a detector (surface 2) in NSC mode. I’m trying to make a macro that shifts the detector along Z-axis using the command SETNSCPOSITION but it doesn't seems to work.The syntax is SETNSCPOSITION surface, object, code, valueCan someone please explains each keyword and how to use it? The surface is the detector surface - 2 ? What is the object? code = 3 for Z Value is the new position?\ THANKS
Python Zemax to SPEOS coating converter
This example is a Python script to convert Zemax coatings to Speos coatings. The script is available here.https://github.com/ansys/optical-automation/blob/main/ansys_optical_automation/application/example_convert_coating_zemax_to_speos.pyThe user inputs are:For each coating + substrate, the software will create a Speos coating. Then the script will combine the two Speos coatings into a .bsdf180 file. The script is using the Transmission vs Angle analysis from OpticStudio. For more information about Ansys optical_automation, click here.
DLL (Source): Non-sequential Astigmatic Gaussian
This Source DLL models an Astigmatic Gaussian Source. It is based on rays but the statistical distribution of rays gives a picture of a diffracting Gaussian beam. It is valid for small angles (paraxial approximation) and when propagating in free space. So clipping at apertures and aberrations will give incorrect results.w0x, w0y are the real beam waist radii (defined at the 1/e2 intensity point) in the XZ and YZ planes. They includes M^2. z0x, z0y are the positions of the beam waist in the XZ and YZ planes. z0<0: in propagation direction if the waist is located before source. M^2x, M^2y are the quality factors in the XZ and YZ planes.For more information, see "Representation of a Gaussian beam by rays" by P. P. Crooker, W. B. Colson, and J. Blau - Physics Department, Naval Postgraduate School, Monterey, California 93943Authors:Steffen Erhard and @Dirk Broemme Click here to download Date Version OpticStudio Version Comment 2020/05/06 1.0 21.1.2 Creation 2023/0
How to ignore Object in API ?
Hello to all,I read the topic about : “how to ignore Surface in API”. I tried to do something similar for non-sequential object but it is not working. surf4 = TheSystem.NCE.GetObjectAt(4) surf4.TypeData.IgnoreObjects = 1First TypeData.IgnoreObjects want a string but I don’t know what to write. Thank you very much in advance fir your answer. Clotilde
how to Ignore Surface in API
I’m still new to the API and having trouble getting and setting the “Ignore this surface” via the API.I’m working in Matlab and trying:TheLDE.GetSurfaceAt(4).GetSurfaceTypeSettings(ZOSAPI.Editors.LDE.ILDETypeData.IgnoreSurface)but get the error:The property 'IgnoreSurface' in class 'ZOSAPI.Editors.LDE.ILDETypeData' must be accessed from a class instance because it is not a Constant property. Can someone point me in the right direction?Thank you,John
Get and Set Folders in Project Preferences of OpticStudio from ZOS API
We can get and set the folders in Project Preferences in OpticStudio using ZOS API.Save the Project Preferences Configuration(.CFG) file in Zemax LLC\Documents\Zemax\Configs or you can use default Project Prefrences configuration file OpticStudio Save Project Prefrences Configuration file Add the following code for connecting saved configuration file Python Code print('\n===PreferencesFile===\n') cfgFile = r"ZemaxLLC\Documents\Zemax\Configs\Project_Prefferences_test.CFG" print(os.path.exists(cfgFile)) if (cfgFile): self.TheConnection.PreferencesFile = cfgFile else: print('Default OpticStudio.CFG preferences used\n') MATLAB Code: fprintf('\n===PreferencesFile===\n') cfgFile = 'C:\Users\Documents\Zemax\Configs\Project_Pre
ZPL Operand: Optimize without vignetting TMA systems
Some time ago, one of our engineers used the ZPL to create a ZPLM for analyzing TMA systems. A ReadMe doc and example file are attached below. Here is a summary of how the ZPLM works:The ZPL actually checks that a surface does not vignette a ray in sequential mode. In sequential mode, a ray only knows about the next (n+1) surface that it's travelling to...the ray doesn't know about previous surfaces or surfaces beyond the next surface. Therefore, you can have surfaces other than n+1 which can clip the ray in real life but SEQ won't detect that. The macro traces a specific marginal ray (±x or ±y) and targets the Mechanical Semi-Diameter of a specific surface. The ZPLM then forces a minimum clearance distance between between the edge of the mirror and the specified marginal ray. Note: The ZPLM has been written with circular apertures in mind. For systems with other aperture types, the code will need to be updated. Additional note: This macro has not been rigorously tested, which is wh
NSC Surface Sag using ZOS-API
The NSC Surface Sag (available in Ansys Zemax OpticStudio 2023 R1 and OpticStudio 23.1) is fully implemented in ZOS-API. It means that you can open that analysis, define the settings and get the results. It makes it easy to convert an object face into a Grid Sag Surface.Here is an example of a Matlab code:TheSystem=TheApplication.PrimarySystem;MyNSCSag = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.NSCSurfaceSag)MyNSCSag.HasAnalysisSpecificSettingsreturns TrueThe settings are:MyNSCSag.ApplyAndWaitForCompletionMyNSCSag_results = MyNSCSag.GetResultsreturns a DataGrid containing the sag pointsSag = MyNSCSag_results.GetDataGrid(0).Values.double;
Exporting volume detector data
Hi, I'm quite new to Zemax and was wondering if someone could assist me with processing some volume detector data. I'm currently trying to reconstruct some data from the volume detector and display it in 3D using the Voxel Maker macro. However, the process tends to be quite slow and often crashes with large models. I've written a Matlab script that will pass a binary array and compute the 3D voxelization. However, I need a way of exporting all of the detector cross-sections from Zemax, so that they can be passed by the script. Does anyone know of a way I can do this? I know I can save the individual images seperately within the detector viewer, however, these images will contain the legend and axis titles. It will also be very time-consuming doing this for 100+ cross-sections. Any help would be greatly appreciated! Regards, Callum Here's the link to the macro I was using for reference: How to show Detector Volume data in 3-D · MyZemax
User Defined Surfare shows only 12 Parameters in LDE
I am new to DLL programming for Zemax. I have an older file using the Fixed-Data 3 standard. This should support 201 parameters. Unfortuneatly in the LDE editor a maximum of 12 Parameter columns are generated even if i define more. Is there a cap of how many parameters can be displayes as input in the LDE?
DLL (User-Defined Surface): Sequential Hexagonal and Staggered Lens Array
These two User-defined surfaces DLL creates an array of hexagonal arranged lenses and an array of staggered lenses. The code is based on us_array.c.us_array_hex.dll has 4 parameters: the number of lenses in X and Y direction and the width and height of each lens.us_array_staggered.dll has 3 parameters: the number of lenses in X and Y direction and the width of the lens.Language: Cpp Click here to download Date Version OpticStudio Version Comment 2018/01/06 1.0 - Creation
Ansys open project on GitHub
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.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 Repository locatio
Only positive values for Chief Ray Coordinates with Merit Function Operands
Hey Everyone! I am currently trying to figure out a way to get the coordinates of the Chief Ray from a Monte Carlo Run so that I get a dataset of Chief Ray coordinates correlating to different lens displacements. I am using the the Merit Function Criterion for the Monte Carlo Run in the Tolerancing tab. My Merit Funtion consists only of the Headers and one operand ( REAY or REAX). The results only give out positive values for the Merit Function but I need it to also show me negative displacements.I am new to ZOS so any help is very appreciated!
How can only OBJECT's Clear Semi-Diameter be enlarged?
How can only OBJECT's Clear Semi-Diameter be enlarged? I mean, I want to increase the size of the object's Clear Semi-Diameter without changing the size of the remaining Lens Surface. Can I know how with below System Explorer Setting? 1. Aperture Type "Float by Stop Size"2. Ray Aiming is "Paraxial"3. Convert Semi-Diameters to Circular Properties in the Lens Data Editor4. Change the field type to 'Object height'.
Python multiprocessing licensing error
Hi I’m currently attempting to run some a series of Physical Optics Propagations in parallel, using pythonnet. They are pretty simple standalone codes which load in a lens file, carry out the propagation and output the coupling. I’ve been using multiprocessing/Pool and have an unusual issue when using too many cpus.The computer I’m using has 16 cpus, but if I were to try and run more than 7 in parallel using Pool, I get a LicenseException (License is not valid for ZOSAPI use), though only for the 8th cpu.I just wondered if you had any insight as to what could be causing this/different recommendations for running the API in parallel in Python. Thanks!
Single Ray Trace in the ZOS-API
In the last few weeks, I have received questions regarding how we can use the ZOS-API to pull single ray trace information. For convenience, I will post my answers here in a single post. I pulled together three different methods for extracting single ray trace data. Below I will list the methods with sample code in Python and Mathematica. I’m happy to provide samples in other languages if needed! If you have other methods you use for this kind of analysis, feel free to add them as a reply! Method 1 - Use the Single Ray Trace analysisThis method can be used to pull the results of the Single Ray Trace analysis window. The benefit of this method is that the results are pulled for all surfaces at once. The drawback of this method is that the data is provided in text form. The output is a TXT file which must be parsed back into the program you are using. This is discussed in a bit more detail here: How to set RayInfo.Vignetted in ZOS-API_Python Python########### Define the constants across
User-operand for refarctive index in non-sequential mode
Hello everyone, EDIT: I was wrong, NPRO’s last parameter is actually the wave number as pointed out by @MichaelH below. Therefore, there’s no need to use a user-defined operandEDIT: new version available in my last reply below! I have made a user operand equivalent to INDX for non-sequential systems.In non-sequential systems, INDX doesn’t work, and one workaround is to use a ZPL operand with the numeric function NPRO using the code 200 (index of refraction of an object). For some time, I used the following code in a ZPLM (I hope the code is self-explanatory but let me know otherwise):object = PVHX()OPTRETURN 0, NPRO(1, object, 200, 0)However, if one has multiple wavelengths defined, it always seem to default to the first one (wave number: 1), and there’s no direct possibility to specify a wavelength in NPRO, whereas this is possible with INDX.A work around is to use the Multi-Configuration Editor with the operand WAVE and a single wavelength defined in the System Explorer. That way, on
retrieving pop beam via ZOS_API Python
Hi, I try to retrieve the output POP field distrubution via python. I looked in the help at IAS_PhysicalOpticsPropagation and couldn't find direct way to do it. I know I can manually save ZBF files and then load, but I need a script as I change parameters and want to retrieve the output beam. How would you advise to do so? Thanks, Leonid
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.