ZEMAX Users' Knowledge Base - http://www.zemax.com/kb
How to Open Consecutively-Named Lens Files Using a ZPL Macro
http://www.zemax.com/kb/articles/128/1/How-to-Open-Consecutively-Named-Lens-Files-Using-a--ZPL-Macro/Page1.html
By Nam-Hyong Kim
Published on 24 August 2006
 

This article demonstrates how to open several lens files using the ZPL macro. This is often useful for analyzing lens files generated by ZEMAX during the Monte Carlo tolerance analysis.


Opening A Series of Files Using a Macro

Sometimes a macro needs to open series of sequentially-named files such as the saved Monte Carlo files. In the case of the saved Monte Carlo files, they are named from MC_T0001.zmx, MC_T0002.zmx to MC_T9999.zmx. The included code snippet changes the value of the myfiles_name$ string variable in the macro such that it contains the proper path and file name of the saved Monte Carlo file in each execution of the FOR loop.

To see the macro, download it from the last page of this article, place it in the {root ZEMAX}Macros directory and open it with any text editor.



The macro is written so that the values of the myfile_name$ is only printed instead of opening the files with those names. When incorporating this code into your own program, replace the PRINT keyword with the LOADLENS keywords to open the lens files instead.

Upon execution of the included macro, you will get the following output window that shows the content of the string variable. 



Summary and References
This article has demonstrated how to change the content of a string variable to match a series of saved Monte Carlo file names. Users can copy and paste the sample code into their own macro to open a series of sequentially-named lens files.