We can use Python or Matlab Interactive Extension to execute Macro using ZPLM. Please take these steps
- Write a ZPLM code that can export JPG or BMP from a given window. GETSYSTEMDATA 1
EXPORTJPG 1, "C:\test\JPG_file\3DLayout"
EXPORTBMP 1, "C:\test\JPG_file\3DLayout"
OPTRETURN 0 You can read more about ExportJPG and EXPORTBMP in our help files: The Programming Tab > About the ZPL > KEYWORDS (about the zpl) > EXPORTJPG - Save the file as ZPL55 or ZPL”Any Number you like”.
- Use this ZPLM in Merit Function Editor. In case if you like to know more about using ZPLM as Operand in Merit Function Operand. Please check this KBA: Optimization using a ZPL Macro: the ZPLM operand. Save this Merit Function as “ExportImage.MF” in folder Zemax LLC\Documents\Zemax\MeritFunction
4.Write Python or Matlab Program to run the ZPLM through Interactive Extension. You can know more about this following this link How to run macro via ZOSAPI Python code: file = r"C:\test\Double Gauss 28 degree.zmx"
TheSystem.LoadFile(file, False)
mf=r" ZemaxLLC\Documents\Zemax\MeritFunction\ExportImage.MF"
TheMFE = TheSystem.MFE
TheMFE.LoadMeritFunction(mf)
TheMFE.CalculateMeritFunction()