Hello Yiska,
You are right, that the MODIFYSETTINGS keywords can be used to change the settings via the Zemax Programming Language (ZPL). However, it is important to understand that this keyword does not make direct changes to the settings of an open analysis window of a specific lens file. Instead, MODIFYSETTINGS makes changes to the configuration files of the analysis features or graphic windows. Each analysis feature and graphic window has its own settings and its own configuration file, and these analysis-specific .CFG files should be used instead of the configuration file of the lens file. Specifically, in your case, to change the settings of the FFT Through Focus MTF analysis, the TFM.CFG file should be used.
In order to make changes, you should follow the procedure below:
- First open your lens file and open a FFT Through Focus MTF analysis.
- In the settings, please click the “Reset” button (in case you have previously saved settings which are not the OpticStudio defaults).
- Then please save the settings by clicking the “Save” button. When the “Save” button is chosen, OpticStudio creates a configuration file with the lens file name but with .CFG extension, as well as a configuration file specific to the chosen analysis feature (for the FFT Through Focus MTF analysis, this is the TFM.CFG). These analysis specific .CFG files exists within the main Zemax\Configs directory, while 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 have modify the analysis-specific configuration file, and not the lens configuration file.
Please note, that in order 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.
So to sum up, in your code you should modify the TFM.CFG file to set up the desired settings for the detector viewer:
configfile$ = 'TFM.CFG'
settingsfilename$ = FileNameStringsBase$ + configfile$
You may find a list below, showing which parameters can be changed for the FFT Through Focus MTF analysis by MODIFYSETTINGS, together with the type codes of these parameters:
Please let us know if you have any further questions!
Hi!
Thanks for the detailed answer.
I tried to work as you suggested (i.e. settingsfilename$ = FileNameStringsBase$ + configfile$) but I got a massage : 'cannot open settings file'.
The macro ran only when I defined: settingsfilename$ = 'TFM.CFG ' ,
but then the settings was not modified- I got TFR data of the saved settings.
I think that somethong is missing... maybe the way of connecting the configuration file with the lens file name and the configuration file specified to the chosen analysis feature.
Thanks!
Hi Yiska,
Thanks for your follow up questions here!
For the settingsfilename, it must include the full path, name, and extension for the file to be modified.
Regarding the error message, this means that the file doesn’t exist or it’s occupied by other processes. The second condition may occur if you have another process/software that is trying to modify the same CFG file.
You could check the followings:
- Have you saved the TFM.CFG file manually beforehand? Please check that you're using the correct full path to the config file. Also, please make sure that you have read and write privileges to the folder and to the file.
- Do you have a second OpticStudio that is also running a macro which accesses the same CFG file? Or are you clicking the “Load” or “Save” buttons in the second OpticStudio? If so, try to close the other OpticStudio and see if you still get same issue.
- Did you open the CFG file with other processes like Notepad, Notepad++, or MATLAB? If so, try to close these processes and see if you still see the issue.
- Finally, when you use the MODIFYSETTINGS keyword on the analysis-specific configuration file, you might need to delete the lens specific config file, as this one can take precedence. Then the Macro should run without problems.
Regarding your other issue, that the macro did not modify the settings, this is probably due to the syntax, please see below:
If you would like to change multiple settings, you need to do this in separate lines. Instead of the single line used in your first comment, you will need 3 lines to change the sampling, the delta focus, and then the frequency, one after the other:
MODIFYSETTINGS settingsfilename$, TFM_SAMP, 5
MODIFYSETTINGS settingsfilename$, TFM_DELTAFOC, 1
MODIFYSETTINGS settingsfilename$, TFM_FREQ, 100
I hope this helps!
Best,
Csilla