access to cfg file

  • 21 May 2020
  • 3 replies
  • 317 views

Badge

Hi


I want to create zpl macro that  print TFR (throogh focus MTF) data to text file. In order to get relevant information I need to change the settings.


I tried to do this by 'MODIFYSETTINGS' but then I got error massage that said 'cannot open setting file'.


I did not find any explanation in Zemax manual where this setting file located and I can create it  such that it can be open. I would like if you can give me some information about this file type and how I can access into it.


Thanks!


 


image of ZPL file:



 


3 replies

Badge

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!


 

Userlevel 5
Badge +2

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:



  1. 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.

  2. 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.

  3. 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.

  4. 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 

Userlevel 5
Badge +2

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:



  1. First open your lens file and open a FFT Through Focus MTF analysis. 

  2. In the settings, please click the “Reset” button (in case you have previously saved settings which are not the OpticStudio defaults).

  3. 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!

Reply