Using macros, written in the Zemax Programming Language (ZPL), is a powerful way to extend the functionality of ZEMAX. Zemax doesn’t provide a special editor for writing ZPL macros, and it recommends using text editors such as the NOTEPAD editor.
I love editors with syntax highlighting. Since there are no standard editors (with syntax highlighting) for writing ZPL codes, I decided to use Notepad++. It also allowed me to create a style-file which enabled syntax highlighting and support minimal code folding as shown below. The style-file contains the latest keyword, numeric function and string function definitions (as of April 2013). I have shared the style-files here in the post.
In order to download the files and see the quick instructions to use them, please continue reading.
Today (05/06/2014) I got to know about another project, created by Xinda Hu, for syntax highlighting and code folding of macro programs for both Zemax and Code V. It seems to be quite sophisticated and uses a modified form of Solarized theme
. It also provides auto-complete and function calltips in the editor, which I believe can be of great help while coding. He has uploaded the required files at his GibHub page here
(Zemax) and here
(Code V). He has also created a GIF animation to demo the capability of his highlighter project, which can be found here
. I highly recommend using his project for ZPL syntax highlighting.
Here is another example of using the same style with bright background.
Firstly, if you are not already using Notepad++
, please download and install it. It is a free but powerful source code editor. The best thing that I like about it is that it is very lightweight, it supports tons and tons of languages, and it allows you to add your own language (as user-defined language) if it is not available in Notepad++ by default.
Once you have installed Notepad++, please run the program.
Download any or both of the following files (the links for the files ZPL Macro (Bright).xml or ZPL Macro (Dark).xml are at the end of the post). As the names suggest, ZPL Macro (Bright).xml is configured for using with a bright background and ZPL Macro (Dark).xml is configured for using with a dark background. (Please note that you can tweak them later.)
Now from the top menu of Notepad++, select “View->User-Defined dialog…” It may take a couple of seconds for Notepad++ to load the User-Defined dialog box shown below (partially).
From the User-Defined dialog, click on the “Import…” button and import the ZPL macro file that you just downloaded.
Now select “ZPL macro” from the “User language” drop-down menu as shown below.
Close the User-Defined dialog box, restart Notepad++, and open an existing ZPL macro file.
When you open the file, the editor will not show any syntax highlighting initially. Click on “Language” from the top panel of Notepad++ and select “ZPL macro” from the bottom of the drop-down panel. The code should be highlighted now. (Unfortunately, you will have to select the language every time you open a ZPL macro or any other user-defined language using the Notepad++ editor.)
You can modify the syntax coloring to suite your own needs by going to “View->User-Defined dialog…”.
Hope you find it useful. Happy ZPL coding.
Links to the files (ZPL codes last updated on 02/18/2014):
More on ZEMAX!!