Skip to main content

Get and Set Folders in Project Preferences of OpticStudio from ZOS API

  • October 5, 2022
  • 1 reply
  • 245 views

Sahil
Forum|alt.badge.img+1

We can get and set the folders in Project Preferences in OpticStudio using ZOS API.

  1. Save the Project Preferences Configuration(.CFG) file in Zemax LLC\Documents\Zemax\Configs or you can use default Project Prefrences configuration file OpticStudio
    Save Project Prefrences Configuration file

     

  2. Add the following code for connecting saved configuration file                                 Python Code                                                               print('\n===PreferencesFile===\n')
    cfgFile = r"ZemaxLLC\Documents\Zemax\Configs\Project_Prefferences_test.CFG"
    print(os.path.exists(cfgFile))
            if (cfgFile):
                self.TheConnection.PreferencesFile = cfgFile
            else:
                print('Default OpticStudio.CFG preferences used\n')                           MATLAB Code:                                                                                                             fprintf('\n===PreferencesFile===\n')
     cfgFile = 'C:\Users\Documents\Zemax\Configs\Project_Prefferences_test.CFG';
     if exist(cfgFile, 'file')
               TheConnection.PreferencesFile = cfgFile;
               fprintf('PreferencesFile: %s\n', char(TheConnection.PreferencesFile))
     else
             fprintf('Default OpticStudio.CFG preferences used\n');
     end
    Python and MATLAB Sample code
    1. Change the code in the BeginApplication method                                  % Add your custom code here...
      % Define variables for Project Preferences 
      Preference = TheApplication.Preferences;
      PrefG = Preference.Folders;
      Logic = {'False', 'True'};
      % Read and print the initial settings
      fprintf('\n===Check initial Settings===\n');
      fprintf('ZplDirectory: %s\n', char(PrefG.ZplDirectory));
      PrefG.ZplDirectory="C:\test\POP\POP\BEAMFILES";
      disp(PrefG.ZplDirectory);
      MATLAB 

          Preference = TheApplication.Preferences
          PrefG = Preference.Folders
          Logic = {'False', 'True'}
          # Read and print the initia settings
          print('\n===Check initial Settings===\n')
          print('ZplDirectory:', PrefG.ZplDirectory)
          PrefG.ZplDirectory="C:\test\POP\POP\BEAMFILES"
          print(PrefG.ZplDirectory)                                                                         

      Python

       

Did this topic help you find an answer to your question?

1 reply

IvanVV
  • Single Emitter
  • 1 reply
  • January 9, 2023

Before finding this post, I had already tried step 3, using MATLAB (standalone mode).  While I could retrieve and display directory paths from Preferences.Folders, I could not change them - trying to set new paths had no effect.

After steps 1 and 2 (preparing and loading a configuration file), ZOSAPI allows me to complete step 3 - changing as well as displaying directory paths.

Many thanks for this post!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings