I would like to open the non-sequential 3d layout in MATLAB. Basically, I would like to customize the 3d viewer so to visualize rays belonging to different paths in different colors. Is there a way to open it via a MATLAB figure?
Best,
Mariangela
Page 1 / 1
Hi Mariangela
You can open the 3D layout if you are working with the Interactive extension, i.e. Matlab is asking OpticStudio to open that window. However if you are working in standalone moce, then there is no way to get some output from the 3D layout because in standalone mode, we do not load all the graphic libraries that are needed for OpticStudio interface.
I am generating a (large) number of configurations using the API. Once the 3D Layout has been opened, is there a way to grab the generated image trough the API?
Thanks!
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
Hi Michael,
That’s a great hack, thank you!!
I cannot figure out one last thing: how to change the settings of the 3D layout with ZOS-API (with Matlab in my case)? I want to plot the lens starting from the surface number 1, but it is starting from number 0 by default.
Could you please help?
Thanks!
-Maria
Hi Maria,
You cannot change the CFG file directly with the API. The only CFG config files you can change are those explicitly documented in the Help Files under the MODIFYSETTINGS keyword in the ZPL section. Rather, you will have to manually change the settings in the 3D Layout window, click the Save button in the button right corner and then run your API script: