Skip to main content
Hello,


I am writing a macro in .zpl. My goal is to define an array of rays in non-sequential mode, whereby each ray has a very specific starting position and direction. I want to trace each ray and save the information about each ray in a .txt file. Above all I am interested in saving the x,y,z-coordinates of the individual ray intercept with the last (detector) surface after the ray went has been reflected my multiple surfaces. Information like it is provided in the .ZRD-file. However I would like to get access to this information with .zpl and zos-api commands, because I need this information for a multitude of rays. In the end I want to have an x- and a y-coordinate for each ray written into the same .txt file.





Until now I have defined the following single ray direction.





FOR yTilt, -yT0/2, yT0/2, step_y             # scan


    FOR zTilt, -zT0/2, zT0/2, step_z         # start,


        


        SETNSCPOSITION 1, 5, 5, yTilt     


        SETNSCPOSITION 1, 5, 4, zTilt     


        NSTR 1, 6, 1, 0, 1, 0, 1, "saverays.ZRD", "", 0   # start non-sequential ray trac





    NEXT zTilt


NEXT yTilt





How do I get access to the results of each raytrace performed in the two FOR-loops? Do I have to save a .ZRD-file for each one and get the information from there? Is there a easier way? I know that there are .zpl-commands for the sequential mode. However, I need the coordinates of intercept for the pure non-sequential mode, because the optics involve many CAD surfaces.





 

Hello Jonas,

Depends what you mean by access. At present time, you can use the ZPL keyword ZRDPLAYBACK to load ray amplitude data on a detector in OpticStudio, and we also offer the possibility to transform a ZRD file into a MAT file for access with MATLAB using ZRD2MAT. Apart from those two keywords, it is not possible to directly access the content of the ZRD files programmatically with ZPL.

My colleague Michael Humphreys wrote a knowledgebase article about Batch Processing of Ray Trace Data using ZOS-API in MATLAB or Python.
 

You do not have to save the rays to a ZRD file as there are two interfaces of the Batch Ray Trace tool in the ZOS-API that can directly retrieve ray data, namely IRayTraceNSCData, and IrayTraceNSCSourceData. The first one is if you want to define the rays to be traced by their x, y, z position, and l, m, n direction, and the second is if you want to trace rays based on a source object already defined in your file. However, those two functions will not return the whole 29 properties available in the ZRD files but only a subset of 18. For example, with those two functions, you cannot get the surface normal.

 

In our experience, if you are using MATLAB or Python, writing and reading the ZRD file can be done efficiently by using the method described in the article of Michael Humphreys, and this comes down to those programming languages being interpreted and not compiled.

 

Let me know if that answers your question , and how you are getting along with the article.


Reply