This article describes a brief ZPL code snippet used to make the setting up of system solves more efficient.
Authored By Mark Nicholson
In larger, more complex systems, it is useful to define solves so as to reduce setup and computation time. Users can set solves by hand, but when more than a few are required, this becomes tedious and time-consuming. To avoid the burden, a Zemax Programming Language (ZPL) macro can be used instead. In this article, we provide the code for such a macro.
This article is written as a companion piece to "How to model a complex Fresnel lens".
Solves are entered by hand in the Editors via a dialog box like so:
The equivalent ZPL macro keyword is SOLVETYPE. The syntax is:
SOLVETYPE surf, CODE, arg1, arg2, arg3, arg4
surf is the surface the solve is being placed on,
CODE defines the solve type, and
arg1-4 are the data entered via the currently greyed-out fields in the solve dialog. Easy!
It is made only slightly harder in pure Non-Sequential Mode, because objects are used instead of individual surfaces, and each object has multiple surfaces of its own. As such,
surf is set to 1, and so
CODE must contain not just the type of the solve, but also the object number it refers to. In addition, for pickup solves, it must also refer to the parameter number of the object that the solve is being applied to. The syntax for
CODE in this case is NSC_PP_o_p, where o is the object number and p is the parameter number.
ZPL has the $STR() function that converts numbers to strings, so this is easy to code up quickly:
! This macro puts pickup solves on parameters 17-26
! of objects 2-5 so that they pick up from the same
! parameter on object 1
from_object = 1
scale_factor = 1
offset = 0
column = 0 #shorthand for 'same column' as the parameter the pickup is on
FOR object = 2, 5, 1
FORMAT 1 INT
object$ = "NSC_PP_" + $STR(object) + "_"
FOR parameter = 17, 26, 1
code$ = object$ + $STR(parameter)
SOLVETYPE 1, code$, from_object, scale_factor, offset, column
The string code$ is set to use the object and parameter number, and then
SOLVETYPE sets the pickup solve quickly on all the parameters so that we pick up from_object = 1, with scale_factor = 1, offset = 0, from the same column as we are currently on.