ZEMAX Users' Knowledge Base - http://www.zemax.com/kb
How to Set Solves from ZPL
http://www.zemax.com/kb/articles/179/1/How-to-Set-Solves-from-ZPL-/Page1.html
By Mark Nicholson
Published on 5 April 2007
 
This article described a brief ZPL code snippet written to save the author from some tedious keyboard data entry. 

This article is also available in Japanese.

Setting Solves from ZPL
This article is also available in Japanese.

Recently, the author wrote a separate Knowledge Base article, which used five Annular Aspheric Lens objects (see here).  Four of the lenses were to be set to pick up the aspheric coefficients of one side from the first, so that a single, smooth aspheric profile resulted on that side of the object. However, this meant setting 40 pick-up solves by hand....tedious. So, a macro was written that quickly automated this tedious keyboard activity.

Solves are entered by hand in the Editors via a dialog box like so:

The solve dialog box

The equivalent ZPL macro keyword is SOLVETYPE. The syntax is

SOLVETYPE surf, CODE, arg1, arg2, arg3, arg4
where 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 slightly harder in pure non-sequential mode, because surf=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 was 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

NEXT parameter
NEXT object


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