- how to save a spot diagram in the MATLAB API after it's generated via the MATLAB API?
- how to change the settings (e.g. view angles) of a 3D Viewer plot in the MATLAB API after it's generated via the MATLAB API?
Hello Yitian,
Thanks for your question here on the forums!
Regarding your first question about saving the Spot Diagram from the API, unfortunately, the analyses specific settings and the analysis specific results are not hooked up for the API for all the analysis types available in Zemax. The best method to review what is available and what is not available is to use the sample code provided in this knowledgebase article:
Generating a list of output data types for each analysis in the ZOS-API · MyZemax
If we run the script in MATLAB we can see that for the Spot Diagram no Data Grids or Data Series are returned, so we cannot pull the raw data to MATLAB. This leaves us with the option of saving the image generated by OpticStudio. But, unfortunately, currently we do not directly support saving images from the API either. The analogue to this function in the user interface (clicking the 'Save' button in the GUI windows) isn't hooked up to the API. However, there is an existing feature request for this capability in our internal system. I have gone ahead and voted for this request on your behalf. Thank you for bringing this to our attention again.
Please keep in mind, that feature requests are weighed based on impact, difficulty to implement, and the number of users who request it. A request is not a guarantee that the feature will be added to a future release. However, these feature requests are very important to us and shape the future of OpticStudio, so we appreciate your input regarding desired functionality.
At this time, there is one possible workaround to this problem, but it will only work in the Interactive Extension. It will not work in a Standalone Application. The workaround involves a ZPL macro using keywords OPENANALYSISWINDOW and EXPORTJPG/EXPORTBMP. You will need to write a ZPLM operand which calls the ZPL macro using those keywords. Then add the ZPLM operand to your Merit Function, and update the Merit Function Editor. In this way, every time when the Merit Function is updated, the ZPL macro will run and an image will be saved. The drawback here is that the Merit Function is updated multiple times when an optimization is running. You will need to be careful about when you include the ZPLM operand and make sure to remove it before optimizing.
You may find more info about this topic in the following forum thread:
Automatically saving analysis windows with ZOS-API · MyZemax
Regarding your second question, about changing the settings of the 3D Viewer from the API, unfortunately the analysis specific settings for the 3D Viewer are not hooked up for the API yet, see the first link. In this case ModifySettings provides a possibility to adjust the settings as shown in Example 17 - Bulk Scatter. But if you check the Help file for the MODIFYSETTINGS keyword, which does the same kind of alterations from the ZPL macro, you can see that there is no codes for the 3D Viewer. You may find more info about this in the Help at:
The Programming Tab > About the ZPL > KEYWORDS (about the zpl) > MODIFYSETTINGS (keywords)
This means, that for this specific analysis we cannot use ModifySettings from the API either. This leaves us with one option, which is that we can save the different settings we would like to run to different configuration files manually from OpticStudio before running any API code, and then we just load the specific config files from the API. To load the desired config file you can run the following lines from MATLAB:
TheSystem = TheApplication.PrimarySystem;
newWin = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.Draw3D);
% Check for analysis specific settings. If the following line returns false, we can use MODIFYSETTINGS to alter the settings:
newWin.HasAnalysisSpecificSettings
analysisSettings = newWin.GetSettings();
cfgFile = ...;
analysisSettings.LoadFrom(cfgFile);
I hope this helps, but if you have any further questions, please let us know and we will be happy to help!
Best,
Csilla
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.