I have created this thread after responding to this question:
because I thought it could be useful to other people who have this question for other analyses.
In ZPL, the keyword MODIFYSETTINGS is used to modify the settings of an analysis. However, MODIFYSETTINGS does not support all the analyses, which raises the question: What shall I do if I can’t edit the settings of my analysis in ZPL with MODIFYSETTINGS.
I’ll start by saying there’s a higher chance that your analysis might have its settings implemented in the ZOS-API. For example, the Geometric Through Focus MTF isn’t available with MODIFYSETTINGS, but is fully imlpemented in the ZOS-API. The drawback is that the ZOS-API has a steeper learning curve, particularly if you’re not familiar with another programing language like Python (or MATLAB).
But what if you absolutely need to use ZPL, and can’t afford to try the ZOS-API?
There is still a roundabout way to modify your analysis settings in ZPL, with some caveats, and I’ll describe it in this post.
Recipe to modify the settings of an unsupported analysis in ZPL
This assumes that you have a tractable list of different settings that you are going to apply sequentially to your analysis.
- Manually open the analysis that you want in your OpticStudio file
- Adjust the settings to your needs
- Press the Save button
- Navigate to your file’s folder
- Rename the *.CFG file that has the same name as your OpticStudio file and add a number to the new name (I’ll give an example below)
- Repeat 2-5 for all the settings that you need (this can be tedious if you have many)
- In ZPL, you can use OPENANALYSISWINDOW to specify which settings should be used for the analysis (this is the *.CFG file you renamed in 5)
How to setup the settings files
For example, I have an OpticStudio file LENS.ZOS, that I open in OpticStudio. I then open a Geometric Through Focus MTF. I change the settings to the following:
- Delta Focus: 0.2
- # Steps: 6
- Use Polarization: True
- Scatter Rays: True
I then press Save and search for the file LENS.CFG in the same folder as my LENS.ZOS. I rename this *.CFG file as LENS_CONFIG00.CFG. I repeat 2-5 with the following settings:
- Delta Focus: 0.5
- # Steps: 5
- Use Polarization: True
- Scatter Rays: False
And I rename the *.CFG file as LENS_CONFIG01.CFG.
Editting the settings with ZPL
The final step is to have your ZPL code search for the different *.CFG files that you created everytime you want to run the analysis with different settings. Here is my code, which I hope is self-explanatory:
![](https://uploads-us-west-2.insided.com/zemax-en/attachment/3864a988-b148-4218-bbe1-0ce0f07632ec.png)
# This script assumes you have < 101
# *.CFG files with a name defined
# as <prefix><XX>.CFG where <XX> is a
# two digit integer starting at 00.
# Lens filepath (without filename)
lens_path$ = $PATHNAME()
# Number of *.CFG files
config_num = 2
# *.CFG file prefix
prefix$ = "LENS_CONFIG"
# Adjust printing format for $STR()
FORMAT "%#02i" LIT
# Print loop starting comment
PRINT "> Apply following configuration file:"
# Loop over the *.CFG files
FOR ii, 0, config_num-1, 1
# New *.CFG file path
new_config$ = lens_path$ + "\" + prefix$ + $STR(ii) + ".CFG"
# Print new *.CFG file path
PRINT "> " + $STR(ii) + ". " + new_config$
# Run Through Focus Geometric MTF with the new *.CFG
OPENANALYSISWINDOW "tfg", new_config$
NEXT
And this is the corresponding output for my example:
![](https://uploads-us-west-2.insided.com/zemax-en/attachment/7f4d666e-e2ce-4159-ba88-62374ff56a6f.png)
![](https://uploads-us-west-2.insided.com/zemax-en/attachment/00ea1bd8-f990-46ae-92e7-407eb3c5dbd1.png)
![](https://uploads-us-west-2.insided.com/zemax-en/attachment/37a44e95-53c4-4525-8eb1-5fa6d8195904.png)
The main caveat is that you need to save all those *.CFG files manually. I’m also attaching all the necessary files to this thread.
I hope this helps, and take care,
David