ZPL Macro syntax highlighting using Notepad++

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!!
I have also written an open-source (MIT license) toolbox called PyZDDE for communicating between ZEMAX and Python (inspired by MZDDE). Using PyZDDE you can use IPython notebook with ZEMAX. You can read more about it in the post titled “Accessing ZEMAX from Python using PyZDDE”, or in the Zemax knowledge-base article “Talking to Zemax using PyZDDE” or directly jump to the github code-base.

9 thoughts on “ZPL Macro syntax highlighting using Notepad++

    • Hi Ms. Greenfingers. Thank you, for your kind words. I am not sure if Notepad++ would be interested or not …. the user-base is not that large I would imagine. By the way, you have a very lovely blog out there, with very nice and colorful photographs.


    • To specify more: It only shows the text of the macro. Copy&paste to create a *xml file with it fails when importing it into notepad++
      Deleting the first line which I considered to be potentially “wrong” (“00″00) doesn’t change that (I could go on editing the file randomly but as I don’t know what I am doing it won’t help I fear).

      • If you only see the text of the macro opened in a browser (after clicking on the link), you can just right click, select “Save as …” and save the file to a directory in your computer.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s