Hi Arvid,
Currently, there is no way to perform something like exporting a BMP file from an analysis output with the API. We do have ZPL keywords like EXPORTBMP and EXPORTJPG which can do this -- is that an approach that you'd be able to take?
Otherwise, what you could likely do is run the analysis of interest with the API and render the data from within whatever application you're working in (Python, MATLAB, etc). That might be the most efficient way to handle exporting a rendering of that data if that workaround suits you. If you'd like a reference, we have a collection of sample codes for the ZOS-API functionality, and Example 4 runs the FFT MTF in OpticStudio and renders the data natively in the application. Different code files can be found at '{Zemax}\ZOS-API Sample Code':
Please let us know if you have any continued questions on this, and we'll be happy to discuss further. Thanks!
~ Angel
Hi Angel,
I'm experimenting with EXPORTBMP and EXPORTJPG and they do what I'm looking for. Thanks!
Can EXPORTBMP and EXPORTJPG or another macrofunction also create directories? right now, if the folder does not exists where I try to write the file I get and error. If not perhaps I could direct the directory in python and then call the macro in python? Can macros be called from the ZOS-API?
I'm also trying to pull the data as in the example you suggested. However, I do not understand how I can identify an already open analysis window in the loaded zmx file.
Could you provide an example or python code or which function I should call for that?
Thanks again
Arvid
Hi Arvid,
To my knowledge, I do not believe that ZPL can create directories -- the examples I've seen have had folders pre-made to allow files to be created. However, you could take the approach of using the API to create a directory. I should note that there is no 'direct' way to run a macro through the API, though. There is a bit of a workaround in that you could write a macro to run with the ZPLM Merit Function operand. The idea would be to 'retrieve' the value of the ZPLM while it actually runs an EXPORTBMP/JGP keyword and saves files. As an example, you might have some ZPL code that looks as follows (from a colleague who wrote a similar script for opening 10 files in sequence and exporting a specific window):
path$ = '**DEFINE PATH HERE**'
prefix$ = 'MC_T'
number_of_files = 10
IF (number_of_files > 9999) THEN number_of_files = 9999
FORMAT '%#04i' LIT # Use the C language format %#041 (4-digit integers 0000, 0001 to 9999)
FOR index, 1, number_of_files, 1
suffix$ = $STR(index)
myfile_name$ = path$ + prefix$ + suffix$ + '.zmx'
LOADLENS myfile_name$
myfile_name$ = path$ + prefix$ + suffix$ + '_MYBMPFILE'
EXPORTBMP 6, myfile_name$
NEXT
END
The API code could then look something like this:
TheSystem = TheApplication.PrimarySystem;
TheSystem.MFE.GetOperandValue(ZOSAPI.Editors.MFE.MeritOperandType.ZPLM,21,0,0,0,0,0,0,0)
This technique will only work as an Interactive Extension, though, as the Interactive Extension guarantees that the required libraries to open and generate analysis plots as the actual GUI is loaded. If you run it as a Standalone Application, these libraries are suppressed, and so you will get empty images exported.
As for loading in data for an already-existing window, I think you would need to know the window index of your open window. With that, you could 'grab' that analysis window with Get_AnalysisAtIndex():
With that, you can run all the functions needed to pull the data on your existing window.
Please let us know if you have any more questions here!
~ Angel