Skip to main content

I am wanting to use a macro to automatically run and store image simulations using a ZPL Macro. Does anyone have example code? 

Hi Karen,



 



It depends on what you want from that analysis window, and whether you intend to change the settings in between different uses.



If you want the result from Image Analysis as if you'd have typed a file name in the Output File settings, and if you don't mind the image being overwritten. Then, you can save your Image Analysis settings, and then simply use:





OPENANALYSISWINDOW 'sim'


Lookup the OPENANALYSISWINDOW keyword if you have relocated the setting file for Image Analysis.



If you rather want the result as if you'd have pressed the floppy icon from Image Analysis, then the keyword you need is EXPORTBMP, or EXPORTJPG and the code can be something like:





OPENANALYSISWINDOW 'sim'

# Analysis window number

sim_window = WINL()

# File path

path$ = 'E:\MYBMPFILE'

# Export window to BMP

EXPORTBMP sim_window, path$


If you need something more involved, I'd recommend using the ZOS-API for this kind of task. It'll give you more freedom to get the results that you want.



Let me know if this is clear, and take care,



 



David


Hi David,

Thank you for your useful answer.

By doing your method, I observed that a duplicate file of the exported image is created in the folder “IMAFiles” of Zemax root folder. Do you have any idea to avoid this? My aim is to save time in a loop for example of a lot of image simulations.

Robin


Hi @Robin.Pierron,

I’m not aware of setting to avoid that. As a simple option, you could use DELETEFILE command in ZPL to ensure that the IMAFiles folder doesn’t get inundated with every saved image.

As David mentioned, you can achieve this also with the ZOS API, which will give you more options and other language native means to manage the files.

Best,
Ethan


I have done this in the past using a for loop to append a timestamp or sequence number to the file name. I don’t have access to that code any longer, but the goal was to use Geometric Image Analysis to look at the shape of a “collimated” beam from a multimode fiber, as a function of distance from the collimator lens. I used EXPORTJPG in the for loop. It worked pretty well, and I was able to combine the images into a movie file using other software. 

One shortcoming to this is the inability to add a text note to the Geometric Image Analysis window using ZPL. I would have liked to label each distance step on the actual image. Maybe there is a way to access the Annotation tools (box, arrow, line, text) from ZPL, but I haven’t found it. Perhaps ZOS-API would be able to accommodate this. 


Reply