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.
While running the unit tests for ZOSPy, I discovered that calling Application.GetSystemAt(0) throws a System.ArgumentOutOfRangeException . This is rather weird, since the primary system should always be present. Upon further inspection, Application.NumberOfOpticalSystems turned out to be 0.I tried to reproduce this problem in C#, and succeeded. The problem also occurs in this example:bool isInitialized = ZOSAPI_Initializer.Initialize();var connection = new ZOSAPI_Connection();var application = connection.ConnectAsExtension(0);Console.WriteLine(application.NumberOfOpticalSystems); // --> 0var systemZero = application.GetSystemAt(0); // --> Throws ArgumentOutOfRangeExceptionBut not in this one, while the new surface added at the end doesn't appear in the GUI (indicating it is not interacting with the primary system):bool isInitialized = ZOSAPI_Initializer.Initialize();var connection = new ZOSAPI_Connection();var application = connection.ConnectAsExtension(0);Console.WriteLine(appli
Hi guys, I am new to learning ZPL. I have a list of macros that I am tasked to write at work. Here are the list below with their purpose. I was hoping anyone have written similar macro, p[lease share or give me tips on how to write them. Thanks.Compute the paraxial ABCD matrix between 2 surfaces. Bend a lens. Given one radius, compute the other radius to maintain the focal length. Macro to plot and optionally list the distortion over the full image format Calculate relative or absolute dn/dT values based on the Schott equations Draw the aperture(s) associated with a surface. Define a macro function to compute the clearance between two surfaces, including the sags of the two surfaces Compute the angular boresight error in object space of the system due to the decentration of a surface or a group of surfaces. Compute the edge thickness between two surfaces at a specified x,y location Plot the FOV points Tabulate the focal lengths of each component in the specified surface range. A compon
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
Hello, I want to push into my model an input file with data regarding new position/ parameters.When I execute the ZPL code through the GUI (Programing>Edit/Run, F9) it works just fine, but when I try to execute it through the merit function with a ZPLM row it seems that the SETNSCPARAMETER/ SETNSCPOSITION just isn’t working.I know the MFE is executing the ZPLM since I made a debug output which looks just fine, feels like I’m missing something very basic.Code snippet:OPEN INPUT_FILENAMEOUTPUT OUTPUT_FILENAMEREAD NUM_OF_PARAMS NUM_OBJPRINT NUM_OF_PARAMS, " ", NUM_OBJFOR II, 1, NUM_OF_PARAMS, 1 READ PARAM_NUMBER PARAM_VALUE PRINT PARAM_NUMBER, " ", PARAM_VALUE SETNSCPARAMETER 1, NUM_OBJ, PARAM_NUMBER, PARAM_VALUENEXTCLOSE An input/output example of the code above:## INPUT ##3 181 50 2 50000.0 3 0.005## OUTPUT ##3.0000 18.00001.0000 50.00002.0000 50000.00003.0000 0.0050 Edit: Wanted to point out that my ZPL files are located in Zemax/Macros
I am writing some python code using PyCharm to generate a non-sequential file from scratch. I’ve used the Zemax API extensively in the past for similar projects which either add or modify lots of rows in sequence, but I haven’t run any of those since before the Ansys merger. Now I’m starting to see some strange behavior as I debug. I have commands which I know and can verify work, even simple ones like:TheNCE.AddObject()While the program is running, it has no issues with these lines. If I save the file and open it, I can see everything is being added, comments are being set, colors are being set, etc. etc. The code works. But once I reach a break point and start debugging, I start getting this error, even when I run these commands that again, I have confirmed work as expected:System.Runtime.Remoting.RemotingException: Failed to write to an IPC Port: The pipe is being closed.I did some Googling and while I see some issues relating to server communication, I don’t see any references to Z
I am using zos api at pythonThe api is very good interface to expand my works.But, there are some questions.I want general information of the lens from prescriptionReport.I find a way to get the data from the code below. prescriptionReport = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.PrescriptionDataSettings) prescriptionReport.ApplyAndWaitForCompletion() prescriptionResults = prescriptionReport.GetResults() However, i cannot find extract data from the “prescriptionResults.”The only way i know is export the prescriptionResults to a text file and read it.i want some way to access the results of prescriptionResults . I am calculating Hygens PSF. It was not difficult to caluculate PSF map form zos-apiThere are important data in header to utilze the PSF.I used “headdata=result.get_HeaderData()”, but headdata does not have any data.I want headerdata of PSF. Thank you all
Hi all, I am looking to build an API in MATLAB to perform image simulations in Zemax. I am having trouble with the basic case.My MATLAB Standalone Application:function  = BeginApplication(TheApplication, filename)import ZOSAPI.*;TheSystem = TheApplication.PrimarySystem;TheSystem.LoadFile(filename, false);% Create analysisim_analysis = TheSystem.Analyses.New_ImageSimulation();im_settings = im_analysis.GetSettings();im_settings.OutputFile = 'testfinal.BMP';im_analysis.ApplyAndWaitForCompletion();end If I run this on the “Double Gauss 5 degree field.zmx” sample file, I get an image generated that simply [0,0,0] pixels.I can run the simulation on the same .zmx file in OpticsStudio without issue. Any ideas what I am doing wrong?
I use a cylinder volume with a scatter model (gaussian) in the front face to implement a generic diffuser.Among other parameters, the scatter model is adjusted through the sigma value.Using the following code does not result in the sigma value being updated:o11 = TheSystem.NCE.GetObjectAt(11)coat_scatter = o11.get_CoatScatterData()coat_scatter.GetFaceData(1).CurrentScatterModelSettings.set_Sigma(1.2)Alternatively, using the following code also does not update sigma:coat_scatter_face_1.CurrentScatterModelSettings.Sigma = 1.5 Does anyone had a similar experience? How to address this problem? Kind regards!
Hi,I am unable to find DOESAG.zpl macro for getting the sag values for the diffractive aspheric surface. Earlier it was available in the knowledge base but now that is also not there. Can I get this macro as it is very useful to view the steps of diffractive surface and surface sag dataRegardsJ Himavanth kumar
Hi all, I’ve seen a few discussions about ellipsoids in non-sequential mode. Notably, @David has shown how the Standard Lens object could be used to build ellipsoids with at least one axis of rotational symmetry in his remarkable answer to the post: Modelling an ellipsoidal volume in non-sequential mode. The Help File also has a section called “Modeling an ellipsoid with the Biconic surface” (The Setup Tab > Editors Group (Setup Tab) > Lens Data Editor > Sequential Surfaces (lens data editor) > Biconic), and the Biconic Surface is also available as a non-sequential object. However, I did not manage to recreate the ellipsoid as depicted in the Help File, which is certainly my fault. In light of the above, I thought it would be a good idea to program a DLL for an ellipsoid object. At the very least, it should have some educational value. You can find the current result of this work in this repository: https://github.com/Omnistic/ellipsoid_object.Here is an example (I’m using
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(
I have a macro that converts .tif files to .dat files via the CONVERTIMAGETOGRID keyword and that all works like a charm and it creates wagonloads of .dat files. What I’d like to do next is import those files into a prescription with an established Grid Phase surface via the same macro . . . but I don’t see a ZPL way to do that?Anybody have any ideas?Thanks!
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.
I am trying to run a boilerplate script to communicate with ZOS-API using MATLAB but I run into some errors during initialization. The path returned by winqueryreg() is valid and added to the Matlab path, but the Helper DLL doesn’t load correctly. Why might be the reason for this error? Thanks!
Hello everyone, I just wanted to share some work I’ve been doing today with adding easing to animations for OpticStudio.In March 2021, Dan Hill published his fine article: How do I create presentation quality graphics and animations? At the end of the article, Dan demonstrates how to produce a 360 degree animated GIF using ZPL.However, one may want to rotate an object over a smaller angular range, and go back and forth from the original position. If you were to do so naively using Dan’s approach, every frame would be at a fixed angular position from the previous one, and you would obtain a “linear” GIF. However, you can obtain a slightly different result if you apply an easing function. There’s an outstanding website, called https://easings.net/, that demonstrates how to make use of such easing functions and the website also includes the formulas necessary to calculate these easing functions.Let me demonstrate the result with an example first, and then show you the workflow I used.I wa
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?
Hello,Python's latest version 3.10 was released a few days back. Our ZOSAPI- Python User updated Python's older version to 3.10 which is not recommendable for Python Interactive and Standalone ZOSAPI -Python. The Pythonnet library which connects CLR of ZOS API dll to Python has not been updated for Python 3.10. So, if you find customers using Python 3.10 or Python 3.9. It would be better to use python 3.7 or Python3.8. As Pythonnet works well with these versions.As you can see after installing Pythonnet getting Attribute error Addrefrence.Attribute ErrorThanksSahil
How do I set a field position (say field coordinate X) to a variable using ZOS-API in Python?I am accessing the Fields information usingFields = TheSystem.SystemData.FieldsIt seems like the methods within the Fields object are slightly different to the MCE or LDE editors, as I can get a single field doing Fields.GetField(2) but I cannot find a method like SetSolveData(solve), which would work in the MCE.Any idea on how to set a field coordinate to a variable?Thanks.
In Non-sequential mode, there is no feature to make the detector result iso-line. Therefore, if ZOS-API functions such as Python or Matlab are used, iso-line mapping is possible using detector data. This is where the first community post about iso-line comes from Displaying IsoLux Lines | Zemax Community#Define detector object numberdetnum=3# get number of pixels in X, Ydims_bool_return, X_detectorDims, Y_detectorDims = TheNCE.GetDetectorDimensions(detnum, 0, 0)# Create array to store flux data for each pixelpix = length = pix.__len__()while pix.__len__() < X_detectorDims * Y_detectorDims: # loop through pixels, store value in pix length += 1 pix_bool, value = TheNCE.GetDetectorData(detnum, length, 1, 0) pix.append(value)# get size of the detectorXlength = TheNCE.GetObjectAt(detnum).GetObjectCell(ZOSAPI.Editors.NCE.ObjectColumn.Par1).DoubleValueYlength = TheNCE.GetObjectAt(detnum).GetObjectCell(ZOSAPI.Editors.NCE.ObjectColumn.Par2).DoubleValue# make a pixel array to 2D d
In OpticStudio, currently we only support one dimensional grating. However, it's not difficult to simulate 2D grating. Here we will show an example using diffractive DLL.You may compile it with the instructions or use the DLL file attached to this article. Before we start, here are some articles for required background knowledge that we will not repeat in this forum post. How diffractive surfaces are modeled in OpticStudio (KBA) How diffraction ray-tracing is calculated (forum post) Custom DLLs in OpticStudio: An overview of user-defined surfaces, objects, and other DLL types (KBA) How to compile a User-Defined DLL (KBA) Let's simply open the attached cpp file and observe how it works.This example is mainly modified from the built-in sample \Documents\Zemax\DLL\Diffractive\diff_samp_1.c To compile the program as C++ code. We package the functions with extern 'C'. In this example, we only want to return diffraction ray direction and its relative intensity. So setting data = 1
Hi guys,Here is another set of task focus on Energy on a detector. Compute and plot the EOD of a system over a defocus range for the specified field points Shift an optical element over a range of axial shifts and compare the change in EOD Compute and plot the percent EOD (energy on detector) over a linear field. Compute and plot the EOD (energy on detector) for a range of focus shifts Compute and plot the change in EOD (encircled or ensquared energy on a detector) over the 2D rectangular FOV Plot the change in EOD (encircled or ensquared energy on a detector) times the normalized PSA over the FOV. Assumes that the macros EOD_VS_FOV and VIG_VS_FOV have been run. Thank you!
Hi guys,Task 3 Plot the RMS spot size vs. through-focus position. Compute and plot the RMS value of geometric spot size, wavefront error, or strehl ratio over a linear field. Compute and plot the RMS value of geometric spot size, wavefront error, or strehl ratio vs focus position. Compute and plot the RMS value of geometric spot size, wavefront error, or strehl ratio over the two-dimensional FOV Compute and plot the RMS value of geometric spot size, wavefront error, or strehl ratio vs wavelength. Compute and plot the RMS WFE over the FOV. Plot spot diagrams over the 2D rectangular or circular field of view. The field of view is assumed to be centered on-axis. Macro that defines a function that returns the RMS Spot Size at any surface in your system. Can be used to constrain the spot size during optimization Thank you!
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.