How to save detector viewer graphical plot into image file by ZOS-API ?
Hello,
I would like to save graphical plot in detector viewer into a picture file by ZOS-API.
I looked at some similar questions in community but most of those tell that “get numerical data and draw a plot using the numerical data” or “that feature is in request” 1 year go.
So, I am wondering if that feature is implemented already or not.
To me, GUI already has that feature and hence it seems that if there is a function in ZOS-API to call that feature in GUI, it gets the job done.
Does anybody know that?
Regards
Kazu
Page 1 / 1
Hi Kazu,
Thank you for your question here on the forums!
You may easily save the graphical results of the Detector Viewer in the GUI by using the Output Image File option as below:
The corresponding property in ZOS-API is the OutFile property of the Detector Viewer. You may find more details about it in the ZOS-API Syntax Help at the ZOSAPI.Analysis.Settings.RayTracing.IAS_DetectorViewer Interface Reference:
To use this function, I modified the sample code for Example 10 - NSC ZRD Filter String, the MATLAB code would look like the following:
% Open Detector Viewer, view previously saved .zrd file DetectorView = TheSystem.Analyses.New_DetectorViewer(); DetectorView_Settings = DetectorView.GetSettings(); DetectorView_Settings.RayDatabaseFilename = 'e10_API_Raytrace.ZRD'; DetectorView_Settings.ShowAs = ZOSAPI.Analysis.DetectorViewerShowAsTypes.FalseColor; DetectorView_Settings.Filter = 'X_HIT(2, 4)'; % Detector will only display rays which hit object 2 exactly 4 times DetectorView_Settings.OutFile = 'myPic.jpg'; DetectorView.ApplyAndWaitForCompletion(); % Apply Settings to Detector Viewer %! [e10s03_m]
Then you will need to make your own plot in the API with the labels added separately.
Unfortunately, currently we do not directly support saving images from the API. 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.
Thank you very much for your answer and your making the request for implementation.
I understood it depends on its priority.
Meantime, I will follow your suggestion to implement it by myself.
Regards
Kazu
Another vote by me!
Thank you
IGM
Please add my vote as well. I would like to be able to save any of the graphics windows, including layouts, to a png or jpg. It would enable us to export the image and then import it to an interactive Python or Mathematica window. This would allow us to confirm the actions and to produce good documentation easily.
Please add my vote too.
In my case I want to save shaded mode, and there is no “output image file” in the GUI.
analysis.ToFil() returns empty image !
I totally agree with David !
Hi,
I was wondering if there was any update on adding this feature?