Hey George,
Since this is obviously a hack, I’ll put some caveats on it up front:
- Needs to be in Interactive Mode
- If running in a FOR loop (to satisfy the large number of configurations), only the Layout window can be opened
- The ZPL uses winnum which doesn’t change once the window is opened but the API uses an enumerated list from 1-n for all opened windows, so if you open a different analysis, then open the Layout, then close the first window, the ZPL and API would be out of sync
- The code uses the ZPL’s EXPORTJPG to save the Layout, so by default this is set to the current Layout’s windows as seen on your screen (so if the window is small or minimized, you will not get a good image). If you want to save to a constant size, manually change the Setup > Project Preferences > Graphics > Default Export Resolution to Custom. You can then specify the Custom Export Width (in pixels) and the Aspect Ratio. This cannot be changed programmatically.
With that said, you can create a ZPLM with the EXPORTJPG keyword, insert the ZPLM into the Merit Function Editor, update the MFE, and thus save the Layout. The following function (in Python) is a full working example of saving the Layout; the optional suffix will add the given number/string to the end of the default file name (saved to Zemax\ZOSAPI_Images), the optional winnum is the ZPL window number, and the optional updatewin can be set to False if you’re not using it in a loop:
<code in attached file...improperly formatted during original post>
Then, to save the images, you can simply call SaveLayout(TheSystem) to get the image. The attached ZIP/Python was run against the Double Gauss 28 degree field.zmx after being converted to NSC with splitting turned on and an H8 filter string applied and then re-run after deleting O1.
The same logic & limitations can easily be converted to Matlab.
~Michael