How to run macro via ZOSAPI

  • 2 August 2021
  • 0 replies
  • 446 views

Userlevel 5
Badge +3

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

https://support.zemax.com/hc/en-us/articles/1500005490881-Optimization-using-a-ZPL-Macro-the-ZPLM-operand

To run this ZPLM, there are four methods:

  1. Use GetOperandValue() to calculate the ZPLM value

A = TheSystem.MFE.GetOperandValue(ZOSAPI.Editors.MFE.MeritOperandType.ZPLM, 25, 0, 0, 0, 0, 0, 0, 0);

  1. Manually add the ZPLM in the merit function and use ZOSAPI to update the operand value. This can be achieved by CalculateMeritFunction(
  2. 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 ();

  1. 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.

 

 

 

 


0 replies

Be the first to reply!

Reply