Find and share ways to extend the capabilities of OpticStudio.
- 75 Topics
- 154 Replies
The Code Exchange is a moderated community where Zemax users can find or share programming solutions to extend OpticStudio’s capabilities. It can be a macro to read the sag of a surface or a DLL to define a phase surface. Browse through our space to find out what we have or share your own!Just a few things before getting started:These solutions are mostly written by optical engineers and not developers. Use them as a starting point and feel free to improve them. Comment on the post if you make an improvement or find something interesting that could be useful to other users! Do you have a solution to share? Create a topic in the Code Exchange category using the tag Code Exchange. Be sure to include a ReadMe doc. An example template is attached. Once posted, our team will verify it and comment if needed.
This diffraction DLL models a non-paraxial idealized polarizer model that produces a linear polarized transverse electric field. It is an alternative to the Jones matrix, that model polarizers for paraxial fields under normal incidence. The diffractive DLL is only a tool used here to compute the electric field. For more information, check: https://www.researchgate.net/publication/324234609_Non-paraxial_idealized_polarizer_model This DLL works for OpticStudio subscription licenses. The source code is not shared.Author: Michael Cheng Click here to download Date Version OpticStudio Version Comment 2021/12/01 1.0 - Creation
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
Attached python script loads a ZBF and propagate the beam to a specific range with given sampling. And then draw the beam in YZ view.Currently POP doesn’t support YZ view, but we can first save a ZBF file and use this tool to show YZ for desired range in z direction.The settings are as below.The beam will be drawn for the range between d1 and d2. We can specify the sampling with the variable samp. The UseAngularSpectrumPropagator must be True for now. We could update it to support False, but this requires some more complicated stitching process. The wave should be correctly set up with the wavelength in the ZBF, otherwise we would get wrong result. Click here to download Date Version OpticStudio Version Comment 2023/08/14 1.0 23R2 Creation
Hello all,I am new to the ZOS API, and would like to know how to get the file name once the connection has been done. I am using Python and I have tried : TheApplication = TheConnection.ConnectAsExtension(0)TheSystem = TheApplication.PrimarySystemprint(TheSystem.SystemName) but I can’t get the name of the zemax file. Any idea how get it?
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.
The download contains a Python script a script to write an image (JPG) into a Binary BIM Image file. The PNG, GIF, TIFF, and BMP should also be supported but haven't been tested. Click here to download Date Version OpticStudio Version Comment 2022/01/01 1.0 - Creation
This Source DLL models an Hermite-Gaussian Source using ray generated at position and angles following the intensity of the electric field and the angular spectrum. This Source DLL is inspired by the known DLL (Source): Non-sequential Astigmatic Gaussian DLL (Source): Hermite-Gauss take 4 parameters:w0_x, w0_y are the theoretical beam waist of the fundamental mode n_x, m_y are the mode indices in the corresponding directionsAuthors:Oran Meir - TriEye@Eyal Hollander- TriEye References:1. Goodman, J. W. (1996, January 1). Introduction to Fourier Optics. McGraw-Hill Science, Engineering & Mathematics, Ch 3.102. Carter, W. H. (1980, April 1). Spot size and divergence for Hermite Gaussian beams of any order. Applied Optics, 19(7), 1027. https://doi.org/10.1364/ao.19.0010273. Gaussian beam. (2023, September 3). Wikipedia. https://en.wikipedia.org/wiki/Gaussian_beam4. Fourier transform. (2023, September 27). Wikipedia. https://en.wikipedia.org/wiki/Fourier_transform5. DLL (Source): Non-se
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
For both radiometric analysis (for example determining the power incident on a detector) and optimization, the best choice for a source is almost always a pseudo-random source such as a Source Ellipse, with enough analysis rays to provide for smooth statistics. Frequently, this means tens of thousands to millions of rays. For visualization, OpticStudio provides the capability to designate a lesser number of Layout Rays to appear in layout plots. These layout rays are still randomly distributed. If only a few rays are used, they generally do not well represent the design. If enough rays are used to visualize the extent of the volume occupied by rays, then the plot can become crowded.As a solution to this problem, the accompanying DLL files provide the ability to generate, in non-sequential mode, uniform fans and rings of rays similar to those which can be displayed in sequential mode layouts. They are compiled for a Windows 64-bit platform.YFAN.DLL is a source dll which, when installed
This is a sequential surface DLL that models a realistic slant grating by using RCWA. The parameters for this sequential surface is mostly same to the same model in non-sequential mode, where details are introduced below.https://support.zemax.com/hc/en-us/articles/1500005578722-Simulating-diffraction-efficiency-of-surface-relief-grating-using-the-RCWA-methodThe main difference to its equivalence in non-sequential mode is only one diffraction order is allowed in sequential mode. If simulation of multiple orders is desired, users can use multi-configs to work it around.The DLL can be downloaded by downloading and opening the attached ZAR file. The corresponding DLL will be automatically extracted to the folder \Document\Zemax\DLL\Surfaces\Note this DLL is locked to only Premium and Enterprise in Ansys Zemax OpticStudio. Standard and Professional license editios are not allowed. Legacy Zemax OpticStudio is not allowed either. Date Version OpticStudio Version Comment 2023/04/03 1.
This Zemax User-Extension helps set-up or check a system with fibers or lasers in OpticStudio. There are two tabs: one to set-up correctly the System Explorer given the fiber values and a second tab to check that a system has been set-up correctly. Values are also given for POP. Click here to download Date Version OpticStudio Version Comment 2020-05-13 1.0 - Creation
I have surfaces near the focus of an aberrated system and I’m seeing that the Clear Semi-Diameter is being automatically set much smaller than the actual beam size. I know that this is because the surface is in a caustic region and I can set a fixed value rather than leave it as automatic. I’d like to have another option, to size it based on something other than the marginal ray height at the surface. What options do I have?
It is common for illumination design to have complex shapes which are difficult to describe by a mathematical formula. For example, custom collimators, waveguides, reflectors, and so on could be represented by freeform curves. When such optical components are designed in a CAD program, we can't optimize their shape in Zemax after importing CAD files.To overcome this issue, I provide an example of how to convert CAD data of a TIR lens into a parametric surface and optimize it for light collimation.In this example I’m using TIR lens. It consists of TIR surface and refractive surface, as shown below.Reference: Pencil of RaysFirst, we will fit TIR surface.Zemax has a Freeform Z object, which is formed by drawing a cubic spline curve through a series of points in the YZ plane:Our target is to retrieve these YZ pairs from a solid model cross-section via cubic spline interpolation. Spline interpolation can be done in python using scipy.interpolate.CubicSpline(Z,Y):Cubic Spline InterpolationAf
API (Python and MATLAB Interactive Extension) Calculate the Ray Transfer (ABCD) Matrix for thick Lens
To compute the ABCD matrix, OpticStudio traces rays over a very small region centered upon the reference field position. Usually, this is the center of the field of view. OpticStudio allows selection of which field position to use for reference.By default, OpticStudio sets the corner of the field grid in object space to be at the maximum radial field distance. Because object height is linear with the tangent of the field angle, the full width of the field when angles are used to define the field is given byWhere θr is the maximum radial field angle at the corner of the field.The ray coordinates in image space for the very small field of view are used to determine the ABCD matrix components. The use of an ABCD matrix allows for coordinate rotations. If the image surface is rotated, such that a y object coordinate images to both an x and a y image coordinate, the ABCD matrix will automatically account for the rotation. The grid distortion plot shows the linear grid, and then marks the ac
Hi Frequent Posters,As I’m sure anyone who regularly answers questions on here, you can at least run across a response not saving for one reason or another. Zemax has a placeholder warning saying “be sure to wait for your attachment to finish uploading before you submit, or you may lose the content of your post”. The only problem is there is no indication from Zemax that attachments are still uploading. So, if you have a few images and one hasn’t uploaded (for whatever reason), you lose your entire post. This is very frustrating, especially if you have a few paragraphs with several images (I’ve personally lost probably over 8+ hours of creating responses because of this).The CKEditor which the community forum uses unfortunately doesn’t have client-side autosave via localStorage (the editor only has a server-side autosave which kinda defeats the purpose of losing content because it’s not sent to the server).I wrote a tiny Chrome (and Edge) extension that will auto-save your content
This Surface Scatter DLL uses an external data file with spline fit points to generate a rotationally symmetric spline-fit scatter function. Allows for quick/easy custom scatter definitions to be implemented. Spline function is defined via polar angle (with theta=0 centered on the specular ray). External data file consists only of 2 columns: polar angle, and relative radiance.Authors: Zachary Derocher Tim Gustafson - Zemax Click here to download Date Version OpticStudio Version Comment 2020-01-15 1.0 - Creation
This DLL models a Vortex Phase Plate. It is useful in laser applications to convert a Gaussian laser beam into a donut-shaped energy ring. For more information, check the following links:https://www.holoor.co.il/wp-content/uploads/2017/11/vortex_zemax_tutorial.pdfhttps://www.holoor.co.il/application/optical-vortex-phase-plate-application-notes/https://www.holoor.co.il/optical-calculator/vortex-lenses/ The Vortex phase plate is a phase surface: Click here to download Date Version OpticStudio Version Comment 2021/03/20 1.0 - Creation
Dear OpticStudio users, I have created a GitHub repository with a template Python script to write binary source files: https://github.com/Omnistic/BinarySource_OpticStudio I'm hoping this will make it easier for you to write binary sources for OpticStudio in the future. As a reminder from the help file, binary files are 30% as large as equivalent text files, read about 20x faster, and can be left on disk consuming only little RAM. The repository also includes an example script to generate stigmatic Gaussian beams as described by P. Colbourne in his webinar. By generating a binary source file, one can visualize the propagation of a non-sequential stigmatic Gaussian beam given its waist parameters. Note that the beam needs to intercept the surfaces sequentially, this is a dummy example for visualizaiton only. An OpticStudio archive file is also included for demonstration. This archive contains the Gaussian beam shown in the layout below (x_waist = 1 um, and y_waist = 2 um).
The Dynamic Link RCWA DLL provides a live connection between Lumerical and Zemax OpticStudio as discussed in the following Knowledgebase article: Dynamic workflow between Lumerical RCWA and Zemax OpticStudio.The DLL edition must match the release number of Ansys Lumerical. For convenience, we provide all DLL editions here. In the list below, find the version of Ansys Lumerical you have installed on your PC, then download the item below that title.For more information about the DLL and its calculation assumptions, please read the following resources: Dynamic workflow between Lumerical RCWA and Zemax OpticStudio Zemax - Lumerical RCWA dynamic linking updates & known bugs Ansys Lumerical 2023 R1 Download DLL Ansys Lumerical 2023 R1.01 Download DLL Ansys Lumerical 2023 R1.02 Download DLL Ansys Lumerical 2023 R1.03 Download DLL Ansys Lumerical 2023 R2 Download DLL Ansys Lumerical 2024 R1 Download DLL Ansys Lumerical 2024 R1.02 (beta) Download DLL
This ZPL fits a CAD surface to a sequential surface by extracting the coordinates and generating a merit function that contains the coordinates as target. This macro is compatible witha tilted surface. Click here to download Date Version OpticStudio Version Comment 2022-04-20 1.0 22.1 Creation
This is a small tool to help users setting up DLL parameters in a more convenient way. This is mainly useful when we need to set up multiple objects and parameters.Here is a quick user guide about the tool.The cell "From Obj" should be a single integer for object number we want to load DLL parameter settings. The par# is a string only including integer, comma, dash, and spaces. Integers are separated by comma. Dash is used to represent a range of integers. By cliking the button Load Par#, all the parameter numbers from the object defined by "From Obj" will be written in Par# cell. Par Val is a string only including numbers, comma, and spaces. Numbers don't need to be integer and are separaterd by comma. By clicking the button Load Values, the value of parameter number defined by cell Par# in object defined by cell "From Obj" will be collected and written in cell Par Val. The To Objs is a string works similar to Par#. We can define one or multiple objects that the 3 buttons "Set MCE", "
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.