Using ZPL Macro Solves

ZPL Macro solves call a user defined ZPL Macro to determine the solve value. For example, see the keyword "SOLVEBEFORESTOP". For more information on solves see the "Solves" section of the Lens Data Editor in the Setup Tab.

Macro solves work by invoking a user defined ZPL Macro to compute the solve. Any numerical value that can be computed in a macro can be returned to the editor calling the solve macro. The macro may make use of the data that exists elsewhere in the editors, such as previous surfaces. Once the data is computed, the macro uses the keyword SOLVERETURN to pass the data back to the editor.

For a simple example, here is a macro that computes the first -order optical power of the interface between surfaces 1 and 2, and returns this power as the solve value:

n1 = INDX(1)
n2 = INDX(2)
c2 = CURV(2)
SOLVERETURN (n2-n1)*c2

There is a disadvantage to referring to specific surfaces directly by surface number as this macro does. If new surfaces are inserted or deleted, the macro will need to be edited to reflect the new surface numbers. Also, certain features, such as mirror substrate drawing, will not work correctly if macro solves refer to fixed surface numbers. The solution is to use the ZPL function SURC to find surfaces with specific text in the comment column of the Lens Data Editor. Suppose the comment "My Surface" was placed on the desired first surface in the Lens Data Editor. The macro could support the power computation above with this revised macro:

A$ = "My Surface"
SURF = SURC(A$)
n1 = INDX(SURF)
n2 = INDX(SURF+1)
c2 = CURV(SURF+1)
SOLVERETURN (n2-n1)*c2

The surface or object number from which the macro solve is being called can also be extracted using the numeric ZPL SOSO function.

Use surface comments and the SURC function in solve macros whenever possible.

Be aware that when tolerancing, the SURC function will keep returning the original surface number even if additional surfaces are added automatically.

For example, if SURC(surface_name$) returns 10 in the original file, when the file is toleranced it will keep returning 10 even if surfaces are added during the tolerancing.

To avoid this behaviour, use the numeric function SRCN instead.

Next: