Calculations for the surface sag may be automated with the use of a simple ZPL macro (a copy of which is available for download on the last page of this article):

ZPL macro for calculating the surface sag of an NSC object

In this macro, you will be asked to enter both the x- and y-range for the source ray and the number of steps over which that range is covered, just as you would have in the Universal Plot 2D Settings dialog box. The x- and y-position of the source ray is then varied within the specified ranges using the keyword SETNSCPOSITION. Once the source ray has been positioned for each step, the z-coordinate of the ray intercept on the object surface is determined using the NSRA operand, which in the macro is called by using the OCOD and OPEV operands. The initial position of the source ray is determined using the NPOS operand, and before the macro is terminated the source ray is set back to this initial position. Details about the keyword SETNSCPOSITION and the functions OCOD, OPEV, and NPOS can be found in Chapter 22 of the ZEMAX manual.

The output generated by this macro is a table of x, y, and z values for the various source ray positions:

Text output of ZPL macro