Creating Zemax Models with MATLAB

  • 1 July 2020
  • 4 replies
  • 154 views

Hi,


I'm trying to develop a MATLAB script that will automatically create a Zemax optical performance model from a specified design model. This involves copying across some data from the design model, such as surface thicknesses.


I've hit an issue where, after creating the new optical performance model, the editor that originally pointed to the LDE of the design model (DesignLDE) switches to the LDE of the new optical performance model (OptPerfLDE). Therefore, my original idea to extract a surface thickness from DesignLDE and set it as a thickness in OptPerfLDE does not work (since DesignLDE and OptPerfLDE now refer to the same editor).


Is there a way that I can have editors from two different Zemax models available in MATLAB to facilitate copying of data, as described above? Or, do I have to load one model, copy the required data (such as surface thickness) to a variable and then load the other model? If the latter, then it would make sense to grab all the required data in one go at the start of the script rather than loading the models multiple times over the course of the script.


Thanks,


Michael


4 replies

Userlevel 6
Badge +2

Hello Michael


ZOS-API allows the user to create any number of IOpticalSystem’s. On the ZOS-API Syntax Help, this is described here:



So I used the Standalone mode and tried with the following code in Matlab:

 


TheSystem1 = TheApplication.LoadNewSystem('E:\Zemax\Samples\Sequential\Objectives\Cooke 40 degree field.zmx');

TheLDE1 = TheSystem1.LDE;

TheLDE1.GetSurfaceAt(1).Thickness



TheSystem2 = TheApplication.LoadNewSystem('E:\Zemax\Samples\Sequential\Objectives\Apochromat.zmx');

TheLDE2 = TheSystem2.LDE;

TheLDE2.GetSurfaceAt(1).Thickness



TheLDE1.GetSurfaceAt(1).Thickness



It gives


ans =     3.2590


ans =      1


ans =     3.2590


So I believe that works. I initially used the following lines to create the objects. But it didn't work:

 


TheSystem1 = TheApplication.PrimarySystem;

TheSystem1.LoadFile('E:\Zemax\Samples\Sequential\Objectives\Cooke 40 degree field.zmx',false);



In the help, it says 'Gets the primary system'. So I think it might always retrieve the same system.


 


Well let me know if that helps or not. Thank you.


Sandrine

Hi Sandrine,


 


Thanks for the reply - very helpful!


For my 2nd model, I'd like to create a new system rather than load an existing one. I tried:


TheSystem2 = TheApplication.CreateNewSystem


but it looks like I am missing an enumeration or similar. 


Could you help with this?


 


Thanks,


Michael

Hi Again,


I managed to work out the missing enumeration. Correct syntax is:


TheSystem2 = TheApplication.CreateNewSystem(ZOSAPI.SystemType.Sequential)


 


So, I was missing the system type!


 


Thanks again,


 


Michael


 

Userlevel 6
Badge +2

Good! Thank you for letting me know.

Reply