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!!
Hey thanks! This is really useful to me. Now the first thing I do after installing zemax on a new machine is add your zpl definitions to notepad++ 🙂
Thanks a lot for putting in those words. I am glad that you found use for it.
many thanks for this tool – it is extremely useful and simplifies coding in ZPL !
Thanks a lot for your kind words.
Very nice! Perhaps you could let Notepad++ know so that they can add it to the standard list of languages already included in 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.
I rated 2 stars because the XML file links are dead, sadly. 😦
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.
Thanks for your method!
How could I save the file as ZPL file type directly?