There is no direct way to run a macro via ZOSAPI. A workaround of this is to create a ZPLM macro and call this from the merit function.
You can find more about ZPLM in this article:
Optimization using a ZPL Macro: the ZPLM operand
To run this ZPLM, there are four methods:
- Use GetOperandValue() to calculate the ZPLM value
A = TheSystem.MFE.GetOperandValue(ZOSAPI.Editors.MFE.MeritOperandType.ZPLM, 25, 0, 0, 0, 0, 0, 0, 0);
- Manually add the ZPLM in the merit function and use ZOSAPI to update the operand value. This can be achieved by CalculateMeritFunction(
- Manually save the merit function that contains the ZPLM and load the merit function
Here is the most related codes:
mf='C:\Users\yuan.chen\Documents\Zemax\MeritFunction\ZPLM25.MF';
TheMFE = TheSystem.MFE;
TheMFE.LoadMeritFunction(mf);
TheMFE.CalculateMeritFunction ();
- Insert the operand directly using: InsertNewOperandAt() showed in Example 3.
Operand_1.ChangeType(ZOSAPI.Editors.MFE.MeritOperandType.ZPLM);
Operand_1.GetCellAt(2).Value="25";
If you want to add the comment, the cell number is different.
Operand_1.ChangeType(ZOSAPI.Editors.MFE.MeritOperandType.BLNK);
Operand_1.GetCellAt(1).Value='ZPLM 25';
Please notice that if you want to save the picture of analysis window using the ZPL KEYWORD EXPORTJPG, you must run OS using interactive mode. The standalone mode does not contain the libraries needed.