ZPL macro for scaling the weight of a range of optimization operands

Optimization is an interactive process, and often the weighting of operands need to be adjusted to enforce a certain design constraint. This article introduces a quick and simple macro that can be used to scale the weighting of a range of optimization operands.

Authored By Dan Hill


Article Attachments


During optimizaiton, there may be cases where we may wish to increase or decrease the weighting for a range of operands by the same factor. Rather than typing in the new weights one by one, you may use a macro to automate the process. In this article, we provide such a macro, and show how to use it with a quick example. 

Macro definition

While an operand's "Weight" is a property that is easily altered in the Merit Function Editor, it can become tedious to reset or change this value - especially in the case of large systems. Since optimization is an iterative process, the user may find that they need to change the weighting of a large range of operands. Luckily this process may be made easier with the use of the following ZPL macro:

For your convenience, the macro is attached to this article. When downloaded, make sure to move the file into the {Zemax}\Macros folder.

As is shown, three input values are required: the starting operand value, the ending operand number, and the scale factor. If you wish to divide the current weights by a certain factor, enter the multiplicative equivalent. That is, if you wish to divide by a factor of 2, then enter 0.5 as the scale factor when prompted.


Say we want to increase the OPD operand weights for just field 1, shown below:

We can run the macro by selecting Programming Tab...Macro List:

Once selected, the input prompts appear. We want to select operands 6 through 14, and scale by 10:

After running the macro, the Merit Function reflects the resulting operand weights:

Macros like this are very easy to generate. This can serve as a template for creating very similar macros which might perform similar functions in any of the other editors in OpticStudio!

Since the weightings applied to operands in the Merit Function Editor are all relative, there is another way to make quick changes to the weighting of the operands which are a part of the default Merit Function. When building the default Merit Function, the overall weight is user-definable:

So, if you wish to increase or decrease the relative weighting applied to the default Merit Function, simply rebuild the default Merit Function and change the weighting!


Was this article helpful?
0 out of 0 found this helpful



Please sign in to leave a comment.