Macro solves are very general, allowing virtually any computation to be used to determine a solve value. All functions and keywords supported by ZPL are available. There are no differences between ZPL macros executed from the macro menu or executed as a solve. However, you should take care when writing ZPL solves. For example:

  • Many ZPL keywords and some functions should not be used in a macro solve. For example, calling "UPDATE" from the solve will update all solves, which will invoke the macro again, resulting in an infinite loop. Other keywords, such as INPUT, will require the user to enter data every time the solve is called, which may be an enormous number of times.
  • Keywords that set values in the editors or create merit functions should not be used.
  • Macro solves should never depend upon data in the editors that is subsequent to the solve; as this may also create erroneoeus data if the solve is called first and then the source data is modified by a separate, subsequent solve.
  • In general, macro solves should be kept short and simple, avoid lengthy computations, and should not make modifications of any lens data. 
  • Note that if you use a macro solve to compute a radius of curvature in the Lens Data Editor, that all solves for this parameter compute curvature, not radius of curvature. The solve should return the inverse of the radius of curvature for this parameter.
  • You are responsible for error-checking the data returned by the macro. For example, if your macro calls a RAYTRACE function to evaluate a ray parameter on surface 5, you should call the RAYE() function to ensure that no error has occurred. For example, the ray may TIR at an earlier surface, or have have hit an aperture. If an error occurs, you should exit the macro without calling SOLVERETURN. The following code snippet gives an example of how to test for errors. Make sure you do not return a value via SOLVERETURN if an error occurs. This is particularly important during optimization.

ZEMAX makes no attempt to qualify or validate the solve macro. This feature offers great power and flexibility, but must be used carefully.