How to update and change the settings of a graphic window from ZPL

This article describes how to change the settings of a graphic window via the MODIFYSETTINGS ZPL keyword.

Authored By Dan Hill


Article Attachments


Each analysis feature and graphic window has its own settings.  We may change them as we desire, and also change the defaults so that the next time we open the same analysis feature, a certain combination of saved settings is used.  Sometimes, it is desirable to observe how the results of an analysis change as a function of a setting (field number, polarized or unpolarized for example).  This may be done manually, or we can automate the process via the keyword MODIFYSETTINGS in the Zemax Programming Language (ZPL).

The MODIFYSETTINGS keyword does not make direct changes to an open analysis window, so how can we update a graphic window to reflect the changes made to the configuration file?  This article will demonstrate this process.

Setting up the file

To make changes to the settings of an analysis feature via the macro language, the MODIFYSETTINGS keyword is required.  It is important to understand that this keyword does not make direct changes to the settings of an open analysis window.  Instead, MODIFYSETTINGS makes changes to the settings files, also known as the configuration (.CFG) files.  For details on what the configuration files are, click here.

To demonstrate this capability, we will start with the “Double Gauss 28 degree field.zmx” file located in your {Zemax}\Samples\Sequential\Objectives folder.

Open this file and open a Shaded Model plot (Analyze Shaded Model).  In the settings, click the “Reset” button (in case you have previously saved settings which are not the OpticStudio defaults), and then change the Rotation X value to 20º, and the Opacity and Brightness to 50%.


Once the values have been set, save the settings by clicking the “Save” button.

When the “Save” button is chosen, OpticStudio creates a configuration file with the lens file name (in this case, the file is “Double Gauss 28 degree field.CFG”) as well as a configuration file specific to the chosen analysis feature (for the shaded model, this file is called LSH.CFG).  The LSH.CFG file exists within the main Zemax directory.  The lens specific configuration file is saved in the same path as the currently opened lens file.

When changing the settings within the macro language, you must modify the analysis-specific configuration file, e.g. LSH.CFG, and not the lens configuration file.

Note: To ensure that the analysis-specific configuration files located in the main Zemax directory are not perturbed, you may copy and paste the necessary configuration files into a temporary folder, and then use these files in the macro. You may of course also choose to modify the configuration files located in the main Zemax directory with the macro, as illustrated in example provided in the next section.

Writing and executing the macro

In this example, let’s change the Y rotation parameter of the Shaded Model settings within the macro language.  For each incremental change in Y, we can export a screen shot of the updated window.

The syntax for the MODIFYSETTINGS keyword is as follows:

MODIFYSETTINGS settingsfilename, type, value

The settingsfilename is the full path, name and extension of the configuration file to be modified.

The type argument is a text mnemonic that indicates which setting within the file is to be modified.  See a complete list of available type codes in the OpticStudio help file.  For the Shaded Model Y rotation, MODIFYSETTINGS keyword is SHA_ROTY. 

To increment the y rotation from 0 to 360 degrees, we will create a simple FOR loop:

start_y = 0
end_y = 360
step_size = 15

FOR y, start_y, end_y, step_size
    IF (y < 10) THEN y$ = "00" + $STR(y)
    IF (y < 100) & (y > 9) THEN y$ = "0" + $STR(y)
    IF (y > 99) THEN y$ = $STR(y)
    filename$ = prefix$ + "Y Rotation_" + y$ + ext$
    MODIFYSETTINGS settingsfilename$, SHA_ROTY, y
    OPENANALYSISWINDOW "Lsh", settingsfilename$
    EXPORTBMP 1, filename$

PRINT "All Done!"

After the MODIFYSETTINGS command within the FOR loop, the lens is reloaded without using the session file (see the docs on the LOADLENS keyword for details).  The Shaded Model window is then updated.  By reloading the lens file without the session file, the window is updated using the settings in our configuration file instead of the session file.

In this particular example, a total of 24 BMP files are created, each of which shows an incremental rotation about z.  As a result, we can easily create an animation using these saved files.  



Was this article helpful?
0 out of 0 found this helpful



Please sign in to leave a comment.