    

 ## On this page

  

 

 # Example 15 - C# 

 Last update: 17.07.2025 

# <a class="anchor" id="ex15_s1"></a>C#

using System;

using System.Diagnostics;

using System.Threading;

using [ZOSAPI](namespace_z_o_s_a_p_i.xhtml);

using [ZOSAPI.Analysis](namespace_z_o_s_a_p_i_1_1_analysis.xhtml);

using [ZOSAPI.Analysis.Settings](namespace_z_o_s_a_p_i_1_1_analysis_1_1_settings.xhtml);

using [ZOSAPI.Editors](namespace_z_o_s_a_p_i_1_1_editors.xhtml);

using [ZOSAPI.Editors.LDE](namespace_z_o_s_a_p_i_1_1_editors_1_1_l_d_e.xhtml);

using [ZOSAPI.Editors.MFE](namespace_z_o_s_a_p_i_1_1_editors_1_1_m_f_e.xhtml);

using [ZOSAPI.SystemData](namespace_z_o_s_a_p_i_1_1_system_data.xhtml);

using [ZOSAPI.Tools](namespace_z_o_s_a_p_i_1_1_tools.xhtml);

using [ZOSAPI.Tools.General](namespace_z_o_s_a_p_i_1_1_tools_1_1_general.xhtml);

using [ZOSAPI.Tools.Optimization](namespace_z_o_s_a_p_i_1_1_tools_1_1_optimization.xhtml);

using [ZOSAPI.Wizards](namespace_z_o_s_a_p_i_1_1_wizards.xhtml);

 

namespace CSharpStandaloneApplication

{

 class Program

 {

 static void Main(string[] args)

 {

 // Find the installed version of OpticStudio

 bool isInitialized = ZOSAPI_NetHelper.ZOSAPI_Initializer.Initialize();

 // Note -- uncomment the following line to use a custom initialization path

 //bool isInitialized = ZOSAPI\_NetHelper.ZOSAPI\_Initializer.Initialize(@"C:\\Program Files\\OpticStudio\\");

 if (isInitialized)

 {

 LogInfo("Found OpticStudio at: " + ZOSAPI_NetHelper.ZOSAPI_Initializer.GetZemaxDirectory());

 }

 else

 {

 HandleError("Failed to locate OpticStudio!");

 return;

 }

 

 BeginStandaloneApplication();

 }

 

 static void BeginStandaloneApplication()

 {

 // Create the initial connection class

 [ZOSAPI\_Connection](class_z_o_s_a_p_i_1_1_z_o_s_a_p_i___connection.xhtml) TheConnection = new [ZOSAPI\_Connection](class_z_o_s_a_p_i_1_1_z_o_s_a_p_i___connection.xhtml)();

 

 // Attempt to create a Standalone connection

 [IZOSAPI\_Application](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml) TheApplication = TheConnection.[CreateNewApplication](class_z_o_s_a_p_i_1_1_z_o_s_a_p_i___connection.xhtml#aadc54af7d7415a765592acf23d3a08ef)();

 if (TheApplication == null)

 {

 HandleError("An unknown connection error occurred!");

 return;

 }

 

 // Check the connection status

 if (!TheApplication.[IsValidLicenseForAPI](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#a5b8d6c216c668d13d6dcb870698c247f))

 {

 HandleError("Failed to connect to OpticStudio: " + TheApplication.[LicenseStatus](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#a95179eb8038b629caa12397723aacb3a));

 return;

 }

 if (TheApplication.[Mode](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#a8d2a89bafe9778c14f592276e5a5eb19) != [ZOSAPI\_Mode](namespace_z_o_s_a_p_i.xhtml#a254f5f6cb4ff37c2245b456b9bb79d2a).Server)

 {

 HandleError("User plugin was started in the wrong mode: expected Server, found " + TheApplication.[Mode](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#a8d2a89bafe9778c14f592276e5a5eb19).ToString());

 return;

 }

 

 [IOpticalSystem](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml) TheSystem = TheApplication.[PrimarySystem](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#aca8045fe84351622e0ee58814a2a3364);

 

 bool b_load;

 

 // creates new directory

 string strPath = System.IO.Path.Combine(TheApplication.[SamplesDir](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#ae8fc2a9409927955cc362f9262b052bb), @"API\\CS\\e15\_Seq\_Optimization");

 System.IO.Directory.CreateDirectory(strPath);

 

 // Load a double gauss design sample file

 b_load = TheSystem.[LoadFile](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#a6eb1455ac53555ae6f30032d85b63735)(System.IO.Path.Combine(TheApplication.[SamplesDir](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#ae8fc2a9409927955cc362f9262b052bb), @"Short course\\Optical System Design Using OpticStudio\\sc\_dbga1.zos"), false);

 Console.WriteLine("\\n" + "Double Gauss Design:\\n");

 

 //Define path locations

 string SamplesFolder = TheApplication.[SamplesDir](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#ae8fc2a9409927955cc362f9262b052bb);

 string SampleFile = System.IO.Path.Combine(TheApplication.[SamplesDir](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#ae8fc2a9409927955cc362f9262b052bb), @"API\\CS\\e15\_Seq\_Optimization\\OptimizedFile.zos");

 TheSystem.[SaveAs](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#a32d2f472d9a6d3277f3cda76afb6d85d)(SampleFile);

 

 //Define System Explorer

 //Define Aperture

 [ISystemData](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_system_data.xhtml) SystExplorer = TheSystem.[SystemData](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#a4c4e9771e9ea51766885fdd6fb6627f5);

 SystExplorer.Aperture.ApertureType = [ZOSAPI](namespace_z_o_s_a_p_i.xhtml).[SystemData](namespace_z_o_s_a_p_i_1_1_system_data.xhtml).ZemaxApertureType.EntrancePupilDiameter;

 SystExplorer.Aperture.ApertureValue = 20;

 

 //Add 3 fields 

 [IField](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_field.xhtml) Field_1 = SystExplorer.[Fields](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_system_data.xhtml#a86c457ff0635211b4c8ac1816f2b1d25).[GetField](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_fields.xhtml#af2d2ae99d7ecf6e5866de571043f907d)(1);

 [IField](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_field.xhtml) NewField_2 = SystExplorer.[Fields](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_system_data.xhtml#a86c457ff0635211b4c8ac1816f2b1d25).[AddField](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_fields.xhtml#a0fe954d939cbd6c061599037bb2c5d5e)(0, 5.0, 1.0);

 SystExplorer.[Fields](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_system_data.xhtml#a86c457ff0635211b4c8ac1816f2b1d25).[SetFieldType](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_fields.xhtml#a8b5cd1dbb8c9b4889f3ba1ff1653dbc4)([ZOSAPI](namespace_z_o_s_a_p_i.xhtml).[SystemData](namespace_z_o_s_a_p_i_1_1_system_data.xhtml).FieldType.ParaxialImageHeight);

 SystExplorer.[Fields](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_system_data.xhtml#a86c457ff0635211b4c8ac1816f2b1d25).[MakeEqualAreaFields](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_fields.xhtml#a9c69df64e2f69ae9d9df0022f6936d78)(3, 21.6);

 

 //Add 3 wavelengths: F,d,C

 bool slPreset = SystExplorer.[Wavelengths](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_system_data.xhtml#adc3ab867ef04c79e760a3726b9509fa7).[SelectWavelengthPreset](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_wavelengths.xhtml#a8d96b6f0046e8e23bf6a9b60525b95a0)([ZOSAPI](namespace_z_o_s_a_p_i.xhtml).[SystemData](namespace_z_o_s_a_p_i_1_1_system_data.xhtml).WavelengthPreset.FdC_Visible);

 

 //Open a shaded model

 [IA\_](interface_z_o_s_a_p_i_1_1_analysis_1_1_i_a__.xhtml) analysis = TheSystem.[Analyses](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#a830cf50c046528c752605eea3cf5e899).New_Analysis([AnalysisIDM](namespace_z_o_s_a_p_i_1_1_analysis.xhtml#a0a5cf0f456b9510dd8070610bf696de7).ShadedModel);

 analysis.[Terminate](interface_z_o_s_a_p_i_1_1_analysis_1_1_i_a__.xhtml#a764ca87cbb1df1a48d2c6353538094aa)();

 analysis.[WaitForCompletion](interface_z_o_s_a_p_i_1_1_analysis_1_1_i_a__.xhtml#a8ef153c1ce41e66e3352e717905bf543)();

 [IAS\_](interface_z_o_s_a_p_i_1_1_analysis_1_1_settings_1_1_i_a_s__.xhtml) analysisSettings = analysis.[GetSettings](interface_z_o_s_a_p_i_1_1_analysis_1_1_i_a__.xhtml#af82c93423d06452642e5cb31203cc109)();

 string cfgFile = System.IO.Path.GetTempFileName();

 // Save the current settings to the temp file

 analysisSettings.[SaveTo](interface_z_o_s_a_p_i_1_1_analysis_1_1_settings_1_1_i_a_s__.xhtml#a3c196d30f275d5d8e17363b3b702bed7)(cfgFile);

 // make your modifications to it

 //MODIFYSETTINGS are defined in the ZPL help files: The Programming Tab &gt; About the ZPL &gt; Keywords

 analysisSettings.[ModifySettings](interface_z_o_s_a_p_i_1_1_analysis_1_1_settings_1_1_i_a_s__.xhtml#a0bd90efa9aecf2f0f3dc7f8e9ad6f309)(cfgFile, "SHA\_ROTX", "90");

 analysisSettings.[ModifySettings](interface_z_o_s_a_p_i_1_1_analysis_1_1_settings_1_1_i_a_s__.xhtml#a0bd90efa9aecf2f0f3dc7f8e9ad6f309)(cfgFile, "SHA\_ROTY", "0");

 analysisSettings.[ModifySettings](interface_z_o_s_a_p_i_1_1_analysis_1_1_settings_1_1_i_a_s__.xhtml#a0bd90efa9aecf2f0f3dc7f8e9ad6f309)(cfgFile, "SHA\_ROTZ", "0");

 // now load in the modified settings

 analysisSettings.[LoadFrom](interface_z_o_s_a_p_i_1_1_analysis_1_1_settings_1_1_i_a_s__.xhtml#a62cf3f062ab2e3015ffca22e5173d650)(cfgFile);

 // If you want to overwrite your default CFG, copy it after you are done modifying the settings:

 //string CFG\_fullname = System.Environment.GetEnvironmentVariable("USERPROFILE") + "\\\\Documents\\\\Zemax\\\\Configs\\\\Configs\\\\POP.CFG";

 //System.IO.File.Copy(cfgFile, CFG\_fullname, true);

 // We don't need the temp file any more, so delete it

 System.IO.File.Delete(cfgFile);

 // Run the analysis with the new settings

 analysis.[ApplyAndWaitForCompletion](interface_z_o_s_a_p_i_1_1_analysis_1_1_i_a__.xhtml#aff285af72f196b9c4915c531ff9873a4)();

 

 // remove all variables and add a F# solve on last surface radius

 [ILensDataEditor](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_lens_data_editor.xhtml) TheLDE = TheSystem.[LDE](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#a942995136e3c3cf875cc1fde38d33477);

 [IOpticalSystemTools](interface_z_o_s_a_p_i_1_1_tools_1_1_i_optical_system_tools.xhtml) tools = TheSystem.[Tools](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#add3e3631eadf7955b7b341179ff1eff8);

 tools.[RemoveAllVariables](interface_z_o_s_a_p_i_1_1_tools_1_1_i_optical_system_tools.xhtml#a74ba97071e2838cebea60050bc5353a2)();

 [ILDERow](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_l_d_e_row.xhtml) Surface_Last = TheLDE.[GetSurfaceAt](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_lens_data_editor.xhtml#a25b725fa7de9dd2713ed949ac2199b05)(TheLDE.[NumberOfSurfaces](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_lens_data_editor.xhtml#a2d87212901ae5122ba17d1a7a6acce09) - 2);

 [ISolveData](interface_z_o_s_a_p_i_1_1_editors_1_1_i_solve_data.xhtml) Solver = Surface_Last.[RadiusCell](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_l_d_e_row.xhtml#a919d15dd13c02d96f80586ab6cb8f1a1).[CreateSolveType](interface_z_o_s_a_p_i_1_1_editors_1_1_i_editor_cell.xhtml#aab9b45b0e5c224d1fb31bce66888d20d)([ZOSAPI](namespace_z_o_s_a_p_i.xhtml).[Editors](namespace_z_o_s_a_p_i_1_1_editors.xhtml).SolveType.FNumber);

 Solver._S_FNumber.FNumber = 3.1415;

 Surface_Last.[RadiusCell](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_l_d_e_row.xhtml#a919d15dd13c02d96f80586ab6cb8f1a1).[SetSolveData](interface_z_o_s_a_p_i_1_1_editors_1_1_i_editor_cell.xhtml#a5c0cbba814207920589ee69ffcfc0d36)(Solver);

 SampleFile = System.IO.Path.Combine(TheApplication.[SamplesDir](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#ae8fc2a9409927955cc362f9262b052bb), @"API\\CS\\e15\_Seq\_Optimization\\OptimizedFile1.zos");

 TheSystem.[SaveAs](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#a32d2f472d9a6d3277f3cda76afb6d85d)(SampleFile);

 

 //change BFL &amp; run quick focus 

 Surface_Last.Thickness = 40.0;

 [IQuickFocus](interface_z_o_s_a_p_i_1_1_tools_1_1_general_1_1_i_quick_focus.xhtml) QFocus = tools.[OpenQuickFocus](interface_z_o_s_a_p_i_1_1_tools_1_1_i_optical_system_tools.xhtml#a27eb438a1843cddb810b111e4f10b6ab)();

 QFocus.Criterion = [QuickFocusCriterion](namespace_z_o_s_a_p_i_1_1_tools_1_1_general.xhtml#a20d6bbac90c0df7ec303415873b2553b).SpotSizeRadial;

 QFocus.UseCentroid = true;

 QFocus.[RunAndWaitForCompletion](interface_z_o_s_a_p_i_1_1_tools_1_1_i_system_tool.xhtml#a26d8cae18772fd31c1d18525a3b8d9ac)();

 QFocus.[Close](interface_z_o_s_a_p_i_1_1_tools_1_1_i_system_tool.xhtml#a5bfa126385b9d0c5619b1aff9a354d31)();

 SampleFile = System.IO.Path.Combine(TheApplication.[SamplesDir](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#ae8fc2a9409927955cc362f9262b052bb), @"API\\CS\\e15\_Seq\_Optimization\\OptimizedFile2.zos");

 TheSystem.[SaveAs](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#a32d2f472d9a6d3277f3cda76afb6d85d)(SampleFile);

 

 //setup a few variables

 tools.[SetAllRadiiVariable](interface_z_o_s_a_p_i_1_1_tools_1_1_i_optical_system_tools.xhtml#a6a7d9cd6afa85c61deee672063ca6db8)();

 [ILDERow](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_l_d_e_row.xhtml) [Surface1](namespace_z_o_s_a_p_i_1_1_tools_1_1_tolerancing.xhtml#a18ffc5c5c02195e015067483e4439229a6c4ed555a70d463f08be6c7dd75270ba) = TheLDE.[GetSurfaceAt](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_lens_data_editor.xhtml#a25b725fa7de9dd2713ed949ac2199b05)(1);

 [ILDERow](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_l_d_e_row.xhtml) [Surface2](namespace_z_o_s_a_p_i_1_1_tools_1_1_tolerancing.xhtml#a18ffc5c5c02195e015067483e4439229a50ba23165f586b14ed916c6119b06129) = TheLDE.[GetSurfaceAt](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_lens_data_editor.xhtml#a25b725fa7de9dd2713ed949ac2199b05)(2);

 [ILDERow](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_l_d_e_row.xhtml) Surface5 = TheLDE.[GetSurfaceAt](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_lens_data_editor.xhtml#a25b725fa7de9dd2713ed949ac2199b05)(5);

 [ILDERow](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_l_d_e_row.xhtml) Surface6 = TheLDE.[GetSurfaceAt](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_lens_data_editor.xhtml#a25b725fa7de9dd2713ed949ac2199b05)(6);

 [ILDERow](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_l_d_e_row.xhtml) Surface9 = TheLDE.[GetSurfaceAt](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_lens_data_editor.xhtml#a25b725fa7de9dd2713ed949ac2199b05)(9);

 [ILDERow](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_l_d_e_row.xhtml) Surface10 = TheLDE.[GetSurfaceAt](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_lens_data_editor.xhtml#a25b725fa7de9dd2713ed949ac2199b05)(10);

 [ILDERow](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_l_d_e_row.xhtml) Surface11 = TheLDE.[GetSurfaceAt](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_lens_data_editor.xhtml#a25b725fa7de9dd2713ed949ac2199b05)(11);

 

 //Thickness 2, 5, 6, 9, and 11 variable

 [Surface2](namespace_z_o_s_a_p_i_1_1_tools_1_1_tolerancing.xhtml#a18ffc5c5c02195e015067483e4439229a50ba23165f586b14ed916c6119b06129).ThicknessCell.MakeSolveVariable();

 Surface5.[ThicknessCell](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_l_d_e_row.xhtml#a1a76b11528342a51e948b5dc0c55e217).[MakeSolveVariable](interface_z_o_s_a_p_i_1_1_editors_1_1_i_editor_cell.xhtml#a74076350d7578c5d5eabb0a35095f9d1)();

 Surface6.[ThicknessCell](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_l_d_e_row.xhtml#a1a76b11528342a51e948b5dc0c55e217).[MakeSolveVariable](interface_z_o_s_a_p_i_1_1_editors_1_1_i_editor_cell.xhtml#a74076350d7578c5d5eabb0a35095f9d1)();

 Surface9.[ThicknessCell](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_l_d_e_row.xhtml#a1a76b11528342a51e948b5dc0c55e217).[MakeSolveVariable](interface_z_o_s_a_p_i_1_1_editors_1_1_i_editor_cell.xhtml#a74076350d7578c5d5eabb0a35095f9d1)();

 Surface11.[ThicknessCell](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_l_d_e_row.xhtml#a1a76b11528342a51e948b5dc0c55e217).[MakeSolveVariable](interface_z_o_s_a_p_i_1_1_editors_1_1_i_editor_cell.xhtml#a74076350d7578c5d5eabb0a35095f9d1)();

 

 //Thickness 10 pick up from 1

 Solver = Surface10.[ThicknessCell](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_l_d_e_row.xhtml#a1a76b11528342a51e948b5dc0c55e217).[CreateSolveType](interface_z_o_s_a_p_i_1_1_editors_1_1_i_editor_cell.xhtml#aab9b45b0e5c224d1fb31bce66888d20d)([ZOSAPI](namespace_z_o_s_a_p_i.xhtml).[Editors](namespace_z_o_s_a_p_i_1_1_editors.xhtml).SolveType.SurfacePickup);

 [ISolveSurfacePickup](interface_z_o_s_a_p_i_1_1_editors_1_1_i_solve_surface_pickup.xhtml) SolverPickup = Solver.[\_S\_SurfacePickup](interface_z_o_s_a_p_i_1_1_editors_1_1_i_solve_data.xhtml#af7d2c55aebf1c6d10bb4bcd7aaff46b3);

 SolverPickup.Surface = 1;

 SolverPickup.ScaleFactor = 1;

 SolverPickup.Column = [ZOSAPI](namespace_z_o_s_a_p_i.xhtml).[Editors](namespace_z_o_s_a_p_i_1_1_editors.xhtml).[LDE](namespace_z_o_s_a_p_i_1_1_editors_1_1_l_d_e.xhtml).SurfaceColumn.Thickness;

 Surface10.[ThicknessCell](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_l_d_e_row.xhtml#a1a76b11528342a51e948b5dc0c55e217).[SetSolveData](interface_z_o_s_a_p_i_1_1_editors_1_1_i_editor_cell.xhtml#a5c0cbba814207920589ee69ffcfc0d36)(Solver);

 SampleFile = System.IO.Path.Combine(TheApplication.[SamplesDir](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#ae8fc2a9409927955cc362f9262b052bb), @"API\\CS\\e15\_Seq\_Optimization\\OptimizedFile3.zos");

 TheSystem.[SaveAs](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#a32d2f472d9a6d3277f3cda76afb6d85d)(SampleFile);

 

 //define merit function

 //load merit function

 [IMeritFunctionEditor](interface_z_o_s_a_p_i_1_1_editors_1_1_m_f_e_1_1_i_merit_function_editor.xhtml) TheMFE = TheSystem.[MFE](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#ac427705057fa09ec839220a094f3033f);

 [ISEQOptimizationWizard](interface_z_o_s_a_p_i_1_1_wizards_1_1_i_s_e_q_optimization_wizard.xhtml) OptWizard = TheMFE.[SEQOptimizationWizard](interface_z_o_s_a_p_i_1_1_editors_1_1_m_f_e_1_1_i_merit_function_editor.xhtml#a4cf1522e517980dad6eacadb11d00ee1);

 

 //Optimize for smallest RMS Spot, which is "Data" = 1

 OptWizard.Data = 1;

 OptWizard.OverallWeight = 1;

 //Gaussian Quadrature with 3 rings (refers to index number = 2)

 OptWizard.Ring = 2;

 //Set air &amp; glass boundaries

 OptWizard.IsGlassUsed = true;

 OptWizard.GlassMin = 3.0;

 OptWizard.GlassMax = 15.0;

 OptWizard.GlassEdge = 3.0;

 OptWizard.IsAirUsed = true;

 OptWizard.AirMin = 0.5;

 OptWizard.AirMax = 1000.0;

 OptWizard.AirEdge = 0.5;

 //And click OK!

 OptWizard.[Apply](interface_z_o_s_a_p_i_1_1_wizards_1_1_i_wizard.xhtml#ac93e0ac86221c90cf749832e6aa0167e)();

 string mf_filename = System.IO.Path.Combine(TheApplication.[SamplesDir](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#ae8fc2a9409927955cc362f9262b052bb), @"API\\CS\\e15\_Seq\_Optimization\\RMS\_Spot\_Radius.mf");

 TheMFE.[SaveMeritFunction](interface_z_o_s_a_p_i_1_1_editors_1_1_m_f_e_1_1_i_merit_function_editor.xhtml#ac4b50af13fbdf77a03241ab03664b710)(mf_filename);

 TheMFE.[LoadMeritFunction](interface_z_o_s_a_p_i_1_1_editors_1_1_m_f_e_1_1_i_merit_function_editor.xhtml#a1e764f5bd80f5fcea5e054d139b99d8c)(mf_filename);

 SampleFile = System.IO.Path.Combine(TheApplication.[SamplesDir](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#ae8fc2a9409927955cc362f9262b052bb), @"API\\CS\\e15\_Seq\_Optimization\\OptimizedFile4.zos");

 

 // Run local optimization and measure time

 // Local optimization until completion

 Stopwatch stopWatch = new Stopwatch();

 stopWatch.Start();

 

 [ILocalOptimization](interface_z_o_s_a_p_i_1_1_tools_1_1_optimization_1_1_i_local_optimization.xhtml) LocalOpt = TheSystem.[Tools](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#add3e3631eadf7955b7b341179ff1eff8).OpenLocalOptimization();

 if (LocalOpt != null)

 {

 LocalOpt.Algorithm = [ZOSAPI](namespace_z_o_s_a_p_i.xhtml).[Tools](namespace_z_o_s_a_p_i_1_1_tools.xhtml).[Optimization](namespace_z_o_s_a_p_i_1_1_tools_1_1_optimization.xhtml).OptimizationAlgorithm.DampedLeastSquares;

 LocalOpt.Cycles = [ZOSAPI](namespace_z_o_s_a_p_i.xhtml).[Tools](namespace_z_o_s_a_p_i_1_1_tools.xhtml).[Optimization](namespace_z_o_s_a_p_i_1_1_tools_1_1_optimization.xhtml).OptimizationCycles.Automatic;

 LocalOpt.NumberOfCores = 8;

 Console.WriteLine("Local Optimization...");

 Console.WriteLine([String](namespace_z_o_s_a_p_i_1_1_common.xhtml#a3f54742c5ea7ea3449f67a65dea61289a27118326006d3829667a400ad23d5d98).Format("Initial Merit Function {0}", LocalOpt.[InitialMeritFunction](interface_z_o_s_a_p_i_1_1_tools_1_1_optimization_1_1_i_local_optimization.xhtml#ab19b913681bf82d6fbecd65120da6da7)));

 LocalOpt.[RunAndWaitForCompletion](interface_z_o_s_a_p_i_1_1_tools_1_1_i_system_tool.xhtml#a26d8cae18772fd31c1d18525a3b8d9ac)();

 Console.WriteLine([String](namespace_z_o_s_a_p_i_1_1_common.xhtml#a3f54742c5ea7ea3449f67a65dea61289a27118326006d3829667a400ad23d5d98).Format("Final Merit Function {0}", LocalOpt.[CurrentMeritFunction](interface_z_o_s_a_p_i_1_1_tools_1_1_optimization_1_1_i_local_optimization.xhtml#a03af1bad5235250fa376ce743ec7e663)));

 LocalOpt.[Close](interface_z_o_s_a_p_i_1_1_tools_1_1_i_system_tool.xhtml#a5bfa126385b9d0c5619b1aff9a354d31)();

 }

 stopWatch.Stop();

 // Get the elapsed time as a TimeSpan value.

 TimeSpan ts = stopWatch.Elapsed;

 

 // Format and display the TimeSpan value.

 string elapsedTime = [String](namespace_z_o_s_a_p_i_1_1_common.xhtml#a3f54742c5ea7ea3449f67a65dea61289a27118326006d3829667a400ad23d5d98).Format("{0:00}:{1:00}:{2:00}.{3:00}",

 ts.Hours, ts.Minutes, ts.Seconds,

 ts.Milliseconds / 10);

 Console.WriteLine("Time elapsed : " + elapsedTime + "\\n");

 //Console.ReadKey(true);

 

 // run global search

 double GlobalOptimTimeInSeconds = 15;

 [IGlobalOptimization](interface_z_o_s_a_p_i_1_1_tools_1_1_optimization_1_1_i_global_optimization.xhtml) GlobalOpt = TheSystem.[Tools](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#add3e3631eadf7955b7b341179ff1eff8).OpenGlobalOptimization();

 if (GlobalOpt != null)

 {

 GlobalOpt.Algorithm = [ZOSAPI](namespace_z_o_s_a_p_i.xhtml).[Tools](namespace_z_o_s_a_p_i_1_1_tools.xhtml).[Optimization](namespace_z_o_s_a_p_i_1_1_tools_1_1_optimization.xhtml).OptimizationAlgorithm.DampedLeastSquares;

 GlobalOpt.NumberOfCores = 8;

 Console.WriteLine("Global Optimization for " + GlobalOptimTimeInSeconds.ToString() + " seconds...");

 Console.WriteLine([String](namespace_z_o_s_a_p_i_1_1_common.xhtml#a3f54742c5ea7ea3449f67a65dea61289a27118326006d3829667a400ad23d5d98).Format("Initial Merit Function {0}", GlobalOpt.[InitialMeritFunction](interface_z_o_s_a_p_i_1_1_tools_1_1_optimization_1_1_i_global_optimization.xhtml#ac737ac4e98a4b490dac136b7624da562)));

 GlobalOpt.NumberToSave = [ZOSAPI](namespace_z_o_s_a_p_i.xhtml).[Tools](namespace_z_o_s_a_p_i_1_1_tools.xhtml).[Optimization](namespace_z_o_s_a_p_i_1_1_tools_1_1_optimization.xhtml).OptimizationSaveCount.Save_10;

 GlobalOpt.[RunAndWaitWithTimeout](interface_z_o_s_a_p_i_1_1_tools_1_1_i_system_tool.xhtml#ae61b47060b4f3ed933b13d794725984e)(GlobalOptimTimeInSeconds);

 for (int j = 1; j &lt;= 10; j++)

 {

 Console.Write([String](namespace_z_o_s_a_p_i_1_1_common.xhtml#a3f54742c5ea7ea3449f67a65dea61289a27118326006d3829667a400ad23d5d98).Format("{0}: {1}\\n", j, GlobalOpt.[CurrentMeritFunction](interface_z_o_s_a_p_i_1_1_tools_1_1_optimization_1_1_i_global_optimization.xhtml#af0936f4cfb9c280c68f054cc00ae2f6f)(j)));

 }

 GlobalOpt.[Cancel](interface_z_o_s_a_p_i_1_1_tools_1_1_i_system_tool.xhtml#a7802878e38f79b8d8c42a22c83a174b6)();

 GlobalOpt.[WaitForCompletion](interface_z_o_s_a_p_i_1_1_tools_1_1_i_system_tool.xhtml#a9076ae50de72dddc49039fd1378ef3db)(); 

 GlobalOpt.[Close](interface_z_o_s_a_p_i_1_1_tools_1_1_i_system_tool.xhtml#a5bfa126385b9d0c5619b1aff9a354d31)();

 }

 

 //run hammer optimization

 double HammerOptimTimeInSeconds = 15;

 [IHammerOptimization](interface_z_o_s_a_p_i_1_1_tools_1_1_optimization_1_1_i_hammer_optimization.xhtml) HammerOpt = TheSystem.[Tools](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#add3e3631eadf7955b7b341179ff1eff8).OpenHammerOptimization();

 if (HammerOpt != null)

 {

 HammerOpt.Algorithm = [ZOSAPI](namespace_z_o_s_a_p_i.xhtml).[Tools](namespace_z_o_s_a_p_i_1_1_tools.xhtml).[Optimization](namespace_z_o_s_a_p_i_1_1_tools_1_1_optimization.xhtml).OptimizationAlgorithm.DampedLeastSquares;

 HammerOpt.NumberOfCores = 8;

 Console.WriteLine("Hammer Optimization for " + HammerOptimTimeInSeconds.ToString() + " seconds...");

 Console.WriteLine([String](namespace_z_o_s_a_p_i_1_1_common.xhtml#a3f54742c5ea7ea3449f67a65dea61289a27118326006d3829667a400ad23d5d98).Format("Initial Merit Function {0}", HammerOpt.[InitialMeritFunction](interface_z_o_s_a_p_i_1_1_tools_1_1_optimization_1_1_i_hammer_optimization.xhtml#a660870437d3f48d2c9058fccc3d590c0)));

 HammerOpt.[RunAndWaitWithTimeout](interface_z_o_s_a_p_i_1_1_tools_1_1_i_system_tool.xhtml#ae61b47060b4f3ed933b13d794725984e)(HammerOptimTimeInSeconds);

 Console.WriteLine([String](namespace_z_o_s_a_p_i_1_1_common.xhtml#a3f54742c5ea7ea3449f67a65dea61289a27118326006d3829667a400ad23d5d98).Format("Final Merit Function {0}", HammerOpt.[CurrentMeritFunction](interface_z_o_s_a_p_i_1_1_tools_1_1_optimization_1_1_i_hammer_optimization.xhtml#a6e0cb7edb9b3871a903cbfc40860fc60)));

 

 HammerOpt.[Cancel](interface_z_o_s_a_p_i_1_1_tools_1_1_i_system_tool.xhtml#a7802878e38f79b8d8c42a22c83a174b6)();

 HammerOpt.[WaitForCompletion](interface_z_o_s_a_p_i_1_1_tools_1_1_i_system_tool.xhtml#a9076ae50de72dddc49039fd1378ef3db)();

 HammerOpt.[Close](interface_z_o_s_a_p_i_1_1_tools_1_1_i_system_tool.xhtml#a5bfa126385b9d0c5619b1aff9a354d31)();

 }

 

 TheSystem.[SaveAs](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#a32d2f472d9a6d3277f3cda76afb6d85d)(SampleFile);

 Console.WriteLine("Press key to continue\\n");

 Console.ReadKey();

 

 // Clean up

 FinishStandaloneApplication(TheApplication);

 }

 

 static void FinishStandaloneApplication([IZOSAPI\_Application](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml) TheApplication)

 {

 // Note - TheApplication will close automatically when this application exits, so this isn't strictly necessary in most cases

 if (TheApplication != null)

 {

 TheApplication.[CloseApplication](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#ab662a3cc1b97d8632a324b1137fa943b)();

 }

 }

 

 static void LogInfo(string message)

 {

 // TODO - add custom logging

 Console.WriteLine(message);

 }

 

 static void HandleError(string errorMessage)

 {

 // TODO - add custom error handling

 throw new Exception(errorMessage);

 }

 

 }

}

[ZOSAPI.ZOSAPI\_Connection](class_z_o_s_a_p_i_1_1_z_o_s_a_p_i___connection.xhtml)

**Definition:** ZemaxService.cs:198



[ZOSAPI.ZOSAPI\_Connection.CreateNewApplication](class_z_o_s_a_p_i_1_1_z_o_s_a_p_i___connection.xhtml#aadc54af7d7415a765592acf23d3a08ef)

IZOSAPI_Application CreateNewApplication()

Attempts to launch a new instance of Optic Studio in 'headless' mode. Note that although the Optic St...

**Definition:** ZemaxService.cs:864



[ZOSAPI.Analysis.IA\_](interface_z_o_s_a_p_i_1_1_analysis_1_1_i_a__.xhtml)

Base interface for all analysis windows. This interface can be accessed via the I_Analyses interface.

**Definition:** IA_Base.cs:29



[ZOSAPI.Analysis.IA\_.Terminate](interface_z_o_s_a_p_i_1_1_analysis_1_1_i_a__.xhtml#a764ca87cbb1df1a48d2c6353538094aa)

bool Terminate()

Attempt to cancel the currently running the analysis.



[ZOSAPI.Analysis.IA\_.WaitForCompletion](interface_z_o_s_a_p_i_1_1_analysis_1_1_i_a__.xhtml#a8ef153c1ce41e66e3352e717905bf543)

void WaitForCompletion()

Waits for the current analysis to finish running (if applicable).



[ZOSAPI.Analysis.IA\_.GetSettings](interface_z_o_s_a_p_i_1_1_analysis_1_1_i_a__.xhtml#af82c93423d06452642e5cb31203cc109)

IAS_ GetSettings()

Gets the settings for the current analysis.



[ZOSAPI.Analysis.IA\_.ApplyAndWaitForCompletion](interface_z_o_s_a_p_i_1_1_analysis_1_1_i_a__.xhtml#aff285af72f196b9c4915c531ff9873a4)

IMessage ApplyAndWaitForCompletion()

Re-runs the analysis with the current settings and waits for it to finish calculating.



[ZOSAPI.Analysis.Settings.IAS\_](interface_z_o_s_a_p_i_1_1_analysis_1_1_settings_1_1_i_a_s__.xhtml)

Base class for all analysis settings interfaces. This class can be accessed via the IA_ interface.

**Definition:** IAS_Base.cs:25



[ZOSAPI.Analysis.Settings.IAS\_.ModifySettings](interface_z_o_s_a_p_i_1_1_analysis_1_1_settings_1_1_i_a_s__.xhtml#a0bd90efa9aecf2f0f3dc7f8e9ad6f309)

bool ModifySettings(string settingsFile, string typeCode, string newValue)

Changes a single setting in the specified file. See the MODIFYSETTINGS DDE command help documentation...



[ZOSAPI.Analysis.Settings.IAS\_.SaveTo](interface_z_o_s_a_p_i_1_1_analysis_1_1_settings_1_1_i_a_s__.xhtml#a3c196d30f275d5d8e17363b3b702bed7)

bool SaveTo(string settingsFile)

Saves the current settings to the specified file.



[ZOSAPI.Analysis.Settings.IAS\_.LoadFrom](interface_z_o_s_a_p_i_1_1_analysis_1_1_settings_1_1_i_a_s__.xhtml#a62cf3f062ab2e3015ffca22e5173d650)

bool LoadFrom(string settingsFile)

Replaces the current settings with settings read from the specified file.



[ZOSAPI.Editors.IEditorCell.SetSolveData](interface_z_o_s_a_p_i_1_1_editors_1_1_i_editor_cell.xhtml#a5c0cbba814207920589ee69ffcfc0d36)

SolveStatus SetSolveData(ISolveData Data)

Updates the system with the new solve type settings (see also CreateSolveType and GetSolveData).



[ZOSAPI.Editors.IEditorCell.MakeSolveVariable](interface_z_o_s_a_p_i_1_1_editors_1_1_i_editor_cell.xhtml#a74076350d7578c5d5eabb0a35095f9d1)

bool MakeSolveVariable()

Sets the solve type to SolveType.Variable.



[ZOSAPI.Editors.IEditorCell.CreateSolveType](interface_z_o_s_a_p_i_1_1_editors_1_1_i_editor_cell.xhtml#aab9b45b0e5c224d1fb31bce66888d20d)

ISolveData CreateSolveType(SolveType type)

Creates the solve type settings for the specified solve type. Note that SetSolveData must be used to ...



[ZOSAPI.Editors.ISolveData](interface_z_o_s_a_p_i_1_1_editors_1_1_i_solve_data.xhtml)

Base interface for all solve types. This interface can be accesed via the IEditorCell interface....

**Definition:** InterfacesEditors.cs:563



[ZOSAPI.Editors.ISolveData.\_S\_SurfacePickup](interface_z_o_s_a_p_i_1_1_editors_1_1_i_solve_data.xhtml#af7d2c55aebf1c6d10bb4bcd7aaff46b3)

ISolveSurfacePickup _S_SurfacePickup

**Definition:** InterfacesEditors.cs:594



[ZOSAPI.Editors.ISolveSurfacePickup](interface_z_o_s_a_p_i_1_1_editors_1_1_i_solve_surface_pickup.xhtml)

**Definition:** InterfacesEditors.cs:694



[ZOSAPI.Editors.LDE.ILDERow](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_l_d_e_row.xhtml)

All data for a Lens Data Editor surface. This interface can be accessed via the ILensDataEditor inter...

**Definition:** InterfacesLDE.cs:791



[ZOSAPI.Editors.LDE.ILDERow.ThicknessCell](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_l_d_e_row.xhtml#a1a76b11528342a51e948b5dc0c55e217)

IEditorCell ThicknessCell

**Definition:** InterfacesLDE.cs:1010



[ZOSAPI.Editors.LDE.ILDERow.RadiusCell](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_l_d_e_row.xhtml#a919d15dd13c02d96f80586ab6cb8f1a1)

IEditorCell RadiusCell

**Definition:** InterfacesLDE.cs:990



[ZOSAPI.Editors.LDE.ILensDataEditor](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_lens_data_editor.xhtml)

This interface defines all properties and methods needed to interact with the Lens Data Editor....

**Definition:** InterfacesLDE.cs:265



[ZOSAPI.Editors.LDE.ILensDataEditor.GetSurfaceAt](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_lens_data_editor.xhtml#a25b725fa7de9dd2713ed949ac2199b05)

ILDERow GetSurfaceAt(int SurfaceNumber)

Gets the data for the specified surface.



[ZOSAPI.Editors.LDE.ILensDataEditor.NumberOfSurfaces](interface_z_o_s_a_p_i_1_1_editors_1_1_l_d_e_1_1_i_lens_data_editor.xhtml#a2d87212901ae5122ba17d1a7a6acce09)

int NumberOfSurfaces

Gets the number of surfaces in the current system.

**Definition:** InterfacesLDE.cs:292



[ZOSAPI.Editors.MFE.IMeritFunctionEditor](interface_z_o_s_a_p_i_1_1_editors_1_1_m_f_e_1_1_i_merit_function_editor.xhtml)

This interface defines all properties and methods needed to interact with the MRit Function Editor....

**Definition:** InterfacesMFE.cs:491



[ZOSAPI.Editors.MFE.IMeritFunctionEditor.LoadMeritFunction](interface_z_o_s_a_p_i_1_1_editors_1_1_m_f_e_1_1_i_merit_function_editor.xhtml#a1e764f5bd80f5fcea5e054d139b99d8c)

void LoadMeritFunction(string fileName)

Replaces the entire MFE with the specified file contents.



[ZOSAPI.Editors.MFE.IMeritFunctionEditor.SEQOptimizationWizard](interface_z_o_s_a_p_i_1_1_editors_1_1_m_f_e_1_1_i_merit_function_editor.xhtml#a4cf1522e517980dad6eacadb11d00ee1)

ISEQOptimizationWizard SEQOptimizationWizard

Get the Sequential Optimization Wizard; note that this wizard is obsolete and you should use SEQOptim...

**Definition:** InterfacesMFE.cs:647



[ZOSAPI.Editors.MFE.IMeritFunctionEditor.SaveMeritFunction](interface_z_o_s_a_p_i_1_1_editors_1_1_m_f_e_1_1_i_merit_function_editor.xhtml#ac4b50af13fbdf77a03241ab03664b710)

void SaveMeritFunction(string fileName)

Saves the entire merit function to the specified file.



[ZOSAPI.IOpticalSystem](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml)

Represent a complete optical system. A IOpticalSystem corresponds to a single .ZMX file....

**Definition:** Interfaces.cs:687



[ZOSAPI.IOpticalSystem.SaveAs](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#a32d2f472d9a6d3277f3cda76afb6d85d)

void SaveAs(string fileName)

Saves the current system to the specified file. All future calls to Save will use the same file.



[ZOSAPI.IOpticalSystem.SystemData](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#a4c4e9771e9ea51766885fdd6fb6627f5)

ISystemData SystemData

Data for configuring everything in the System Explorer.

**Definition:** Interfaces.cs:845



[ZOSAPI.IOpticalSystem.LoadFile](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#a6eb1455ac53555ae6f30032d85b63735)

bool LoadFile(string LensFile, bool saveIfNeeded)

Replaces the current system with data from the specified file.



[ZOSAPI.IOpticalSystem.Analyses](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#a830cf50c046528c752605eea3cf5e899)

I_Analyses Analyses

Gets the analyses for the current system.

**Definition:** Interfaces.cs:925



[ZOSAPI.IOpticalSystem.LDE](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#a942995136e3c3cf875cc1fde38d33477)

ILensDataEditor LDE

Gets the lens data editor.

**Definition:** Interfaces.cs:865



[ZOSAPI.IOpticalSystem.MFE](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#ac427705057fa09ec839220a094f3033f)

IMeritFunctionEditor MFE

Gets the merit function editor.

**Definition:** Interfaces.cs:910



[ZOSAPI.IOpticalSystem.Tools](interface_z_o_s_a_p_i_1_1_i_optical_system.xhtml#add3e3631eadf7955b7b341179ff1eff8)

IOpticalSystemTools Tools

Gets an interface used to run various tools on the optical system.

**Definition:** Interfaces.cs:932



[ZOSAPI.IZOSAPI\_Application](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml)

This interface contains all information about the current ZOS-API connection, as well as methods for ...

**Definition:** Interfaces.cs:261



[ZOSAPI.IZOSAPI\_Application.IsValidLicenseForAPI](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#a5b8d6c216c668d13d6dcb870698c247f)

bool IsValidLicenseForAPI

Gets a value indicating whether this the API is currently useable.

**Definition:** Interfaces.cs:287



[ZOSAPI.IZOSAPI\_Application.Mode](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#a8d2a89bafe9778c14f592276e5a5eb19)

ZOSAPI_Mode Mode

Gets the current connetion mode. Use this to check if Optic Studio is expecting a user operand / anal...

**Definition:** Interfaces.cs:306



[ZOSAPI.IZOSAPI\_Application.LicenseStatus](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#a95179eb8038b629caa12397723aacb3a)

LicenseStatusType LicenseStatus

Gets the license status. Note that this displays the license edition if successful,...

**Definition:** Interfaces.cs:280



[ZOSAPI.IZOSAPI\_Application.CloseApplication](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#ab662a3cc1b97d8632a324b1137fa943b)

void CloseApplication()

Shut down the Optic Studio process.



[ZOSAPI.IZOSAPI\_Application.PrimarySystem](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#aca8045fe84351622e0ee58814a2a3364)

IOpticalSystem PrimarySystem

Gets the primary system. When Mode is ZOSAPI_Mode.Server, this will initially be an empty sequential ...

**Definition:** Interfaces.cs:328



[ZOSAPI.IZOSAPI\_Application.SamplesDir](interface_z_o_s_a_p_i_1_1_i_z_o_s_a_p_i___application.xhtml#ae8fc2a9409927955cc362f9262b052bb)

string SamplesDir

Gets the full path for the current user's samples directory (in the My Documents\Zemax\Samples\ folde...

**Definition:** Interfaces.cs:505



[ZOSAPI.SystemData.IField](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_field.xhtml)

System field data. This interface can be accessed via the IFields interface.

**Definition:** InterfacesSE.cs:975



[ZOSAPI.SystemData.IFields.AddField](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_fields.xhtml#a0fe954d939cbd6c061599037bb2c5d5e)

IField AddField(double X, double Y, double Weight)

Add a new field, after all the current fields.



[ZOSAPI.SystemData.IFields.SetFieldType](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_fields.xhtml#a8b5cd1dbb8c9b4889f3ba1ff1653dbc4)

void SetFieldType(FieldType type)

Sets the field type definition for all fields.



[ZOSAPI.SystemData.IFields.MakeEqualAreaFields](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_fields.xhtml#a9c69df64e2f69ae9d9df0022f6936d78)

bool MakeEqualAreaFields(int numberOfFields, double maximumField)

Replaces the existing system fields with new fields spread over an equal area.



[ZOSAPI.SystemData.IFields.GetField](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_fields.xhtml#af2d2ae99d7ecf6e5866de571043f907d)

IField GetField(int position)

Gets the specified field.



[ZOSAPI.SystemData.ISystemData](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_system_data.xhtml)

Interfaces and methods for changing all System Explorer data. This interface can be accessed via the ...

**Definition:** InterfacesSE.cs:275



[ZOSAPI.SystemData.ISystemData.Fields](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_system_data.xhtml#a86c457ff0635211b4c8ac1816f2b1d25)

IFields Fields

**Definition:** InterfacesSE.cs:278



[ZOSAPI.SystemData.ISystemData.Wavelengths](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_system_data.xhtml#adc3ab867ef04c79e760a3726b9509fa7)

IWavelengths Wavelengths

**Definition:** InterfacesSE.cs:277



[ZOSAPI.SystemData.IWavelengths.SelectWavelengthPreset](interface_z_o_s_a_p_i_1_1_system_data_1_1_i_wavelengths.xhtml#a8d96b6f0046e8e23bf6a9b60525b95a0)

bool SelectWavelengthPreset(WavelengthPreset preset)

Replaces all system wavelengths with a preset definition.



[ZOSAPI.Tools.General.IQuickFocus](interface_z_o_s_a_p_i_1_1_tools_1_1_general_1_1_i_quick_focus.xhtml)

Interfaces and methods for running the Quick Focus tool. This interface can be accessed via the IOpti...

**Definition:** Tools.cs:793



[ZOSAPI.Tools.IOpticalSystemTools](interface_z_o_s_a_p_i_1_1_tools_1_1_i_optical_system_tools.xhtml)

Methods to run various system-wide tools. This interface can be accessed via the IOpticalSystem inter...

**Definition:** Tools.cs:107



[ZOSAPI.Tools.IOpticalSystemTools.OpenQuickFocus](interface_z_o_s_a_p_i_1_1_tools_1_1_i_optical_system_tools.xhtml#a27eb438a1843cddb810b111e4f10b6ab)

IQuickFocus OpenQuickFocus()

Opens the Quick Focus tool.



[ZOSAPI.Tools.IOpticalSystemTools.SetAllRadiiVariable](interface_z_o_s_a_p_i_1_1_tools_1_1_i_optical_system_tools.xhtml#a6a7d9cd6afa85c61deee672063ca6db8)

int SetAllRadiiVariable()

Makes all radii in the system variable.



[ZOSAPI.Tools.IOpticalSystemTools.RemoveAllVariables](interface_z_o_s_a_p_i_1_1_tools_1_1_i_optical_system_tools.xhtml#a74ba97071e2838cebea60050bc5353a2)

bool RemoveAllVariables()

Removes all variables in the system.



[ZOSAPI.Tools.ISystemTool.RunAndWaitForCompletion](interface_z_o_s_a_p_i_1_1_tools_1_1_i_system_tool.xhtml#a26d8cae18772fd31c1d18525a3b8d9ac)

bool RunAndWaitForCompletion()

Sames as calling Run followed by WaitForCompletion.



[ZOSAPI.Tools.ISystemTool.Close](interface_z_o_s_a_p_i_1_1_tools_1_1_i_system_tool.xhtml#a5bfa126385b9d0c5619b1aff9a354d31)

bool Close()

Closes this tool and frees up and associated resources.



[ZOSAPI.Tools.ISystemTool.Cancel](interface_z_o_s_a_p_i_1_1_tools_1_1_i_system_tool.xhtml#a7802878e38f79b8d8c42a22c83a174b6)

bool Cancel()

Cancels the currently running asynchronous tool.



[ZOSAPI.Tools.ISystemTool.WaitForCompletion](interface_z_o_s_a_p_i_1_1_tools_1_1_i_system_tool.xhtml#a9076ae50de72dddc49039fd1378ef3db)

bool WaitForCompletion()

Waits for the asynchronous tool to complete.



[ZOSAPI.Tools.ISystemTool.RunAndWaitWithTimeout](interface_z_o_s_a_p_i_1_1_tools_1_1_i_system_tool.xhtml#ae61b47060b4f3ed933b13d794725984e)

RunStatus RunAndWaitWithTimeout(double timeOutSeconds)

Starts the tool running, and waits for it to complete with the specified timeout value....



[ZOSAPI.Tools.Optimization.IGlobalOptimization](interface_z_o_s_a_p_i_1_1_tools_1_1_optimization_1_1_i_global_optimization.xhtml)

Interfaces and methods for running a Global Optimization. This interface can be accessed via the IOpt...

**Definition:** Optimization.cs:109



[ZOSAPI.Tools.Optimization.IGlobalOptimization.InitialMeritFunction](interface_z_o_s_a_p_i_1_1_tools_1_1_optimization_1_1_i_global_optimization.xhtml#ac737ac4e98a4b490dac136b7624da562)

double InitialMeritFunction

**Definition:** Optimization.cs:117



[ZOSAPI.Tools.Optimization.IGlobalOptimization.CurrentMeritFunction](interface_z_o_s_a_p_i_1_1_tools_1_1_optimization_1_1_i_global_optimization.xhtml#af0936f4cfb9c280c68f054cc00ae2f6f)

double CurrentMeritFunction(int N)



[ZOSAPI.Tools.Optimization.IHammerOptimization](interface_z_o_s_a_p_i_1_1_tools_1_1_optimization_1_1_i_hammer_optimization.xhtml)

Interfaces and methods for running a Hammer Optimization. This interface can be accessed via the IOpt...

**Definition:** Optimization.cs:170



[ZOSAPI.Tools.Optimization.IHammerOptimization.InitialMeritFunction](interface_z_o_s_a_p_i_1_1_tools_1_1_optimization_1_1_i_hammer_optimization.xhtml#a660870437d3f48d2c9058fccc3d590c0)

double InitialMeritFunction

**Definition:** Optimization.cs:178



[ZOSAPI.Tools.Optimization.IHammerOptimization.CurrentMeritFunction](interface_z_o_s_a_p_i_1_1_tools_1_1_optimization_1_1_i_hammer_optimization.xhtml#a6e0cb7edb9b3871a903cbfc40860fc60)

double CurrentMeritFunction

**Definition:** Optimization.cs:179



[ZOSAPI.Tools.Optimization.ILocalOptimization](interface_z_o_s_a_p_i_1_1_tools_1_1_optimization_1_1_i_local_optimization.xhtml)

Interfaces and methods for running a Local Optimization. This interface can be accessed via the IOpti...

**Definition:** Optimization.cs:50



[ZOSAPI.Tools.Optimization.ILocalOptimization.CurrentMeritFunction](interface_z_o_s_a_p_i_1_1_tools_1_1_optimization_1_1_i_local_optimization.xhtml#a03af1bad5235250fa376ce743ec7e663)

double CurrentMeritFunction

**Definition:** Optimization.cs:71



[ZOSAPI.Tools.Optimization.ILocalOptimization.InitialMeritFunction](interface_z_o_s_a_p_i_1_1_tools_1_1_optimization_1_1_i_local_optimization.xhtml#ab19b913681bf82d6fbecd65120da6da7)

double InitialMeritFunction

**Definition:** Optimization.cs:70



[ZOSAPI.Wizards.ISEQOptimizationWizard](interface_z_o_s_a_p_i_1_1_wizards_1_1_i_s_e_q_optimization_wizard.xhtml)

Interface for the Merit Function, Sequential Optimization Wizard These settings can be retrieved from...

**Definition:** InterfacesWizards.cs:293



[ZOSAPI.Wizards.IWizard.Apply](interface_z_o_s_a_p_i_1_1_wizards_1_1_i_wizard.xhtml#ac93e0ac86221c90cf749832e6aa0167e)

void Apply()

Settings are set, perform the wizardry.



[ZOSAPI.Analysis.Settings](namespace_z_o_s_a_p_i_1_1_analysis_1_1_settings.xhtml)

**Definition:** IAS_FieldCurvatureAndDistortion.cs:5



[ZOSAPI.Analysis](namespace_z_o_s_a_p_i_1_1_analysis.xhtml)

**Definition:** IAS_FieldCurvatureAndDistortion.cs:5



[ZOSAPI.Analysis.AnalysisIDM](namespace_z_o_s_a_p_i_1_1_analysis.xhtml#a0a5cf0f456b9510dd8070610bf696de7)

AnalysisIDM

All available analysis types. See the I_Analyses interface for more information.

**Definition:** I_Analyses.cs:15



[ZOSAPI.Common.SettingsDataType.String](namespace_z_o_s_a_p_i_1_1_common.xhtml#a3f54742c5ea7ea3449f67a65dea61289a27118326006d3829667a400ad23d5d98)

@ String



[ZOSAPI.Editors.LDE](namespace_z_o_s_a_p_i_1_1_editors_1_1_l_d_e.xhtml)

**Definition:** InterfacesLDE.cs:8



[ZOSAPI.Editors.MFE](namespace_z_o_s_a_p_i_1_1_editors_1_1_m_f_e.xhtml)

**Definition:** InterfacesMFE.cs:12



[ZOSAPI.Editors](namespace_z_o_s_a_p_i_1_1_editors.xhtml)

**Definition:** InterfacesEditors.cs:12



[ZOSAPI.SystemData](namespace_z_o_s_a_p_i_1_1_system_data.xhtml)

**Definition:** InterfacesSE.cs:11



[ZOSAPI.Tools.General](namespace_z_o_s_a_p_i_1_1_tools_1_1_general.xhtml)

**Definition:** Tools.cs:697



[ZOSAPI.Tools.General.QuickFocusCriterion](namespace_z_o_s_a_p_i_1_1_tools_1_1_general.xhtml#a20d6bbac90c0df7ec303415873b2553b)

QuickFocusCriterion

**Definition:** Tools.cs:767



[ZOSAPI.Tools.Optimization](namespace_z_o_s_a_p_i_1_1_tools_1_1_optimization.xhtml)

**Definition:** Optimization.cs:9



[ZOSAPI.Tools.Tolerancing.TolerancingParameterName.Surface2](namespace_z_o_s_a_p_i_1_1_tools_1_1_tolerancing.xhtml#a18ffc5c5c02195e015067483e4439229a50ba23165f586b14ed916c6119b06129)

@ Surface2



[ZOSAPI.Tools.Tolerancing.TolerancingParameterName.Surface1](namespace_z_o_s_a_p_i_1_1_tools_1_1_tolerancing.xhtml#a18ffc5c5c02195e015067483e4439229a6c4ed555a70d463f08be6c7dd75270ba)

@ Surface1



[ZOSAPI.Tools](namespace_z_o_s_a_p_i_1_1_tools.xhtml)

**Definition:** FileSource.cs:4



[ZOSAPI.Wizards](namespace_z_o_s_a_p_i_1_1_wizards.xhtml)

**Definition:** InterfacesWizards.cs:10



[ZOSAPI](namespace_z_o_s_a_p_i.xhtml)

The ZOSAPI namespace contains classes for initially connecting to zemax. See also ZOSAPI_Connection,...

**Definition:** IAS_FieldCurvatureAndDistortion.cs:5



[ZOSAPI.ZOSAPI\_Mode](namespace_z_o_s_a_p_i.xhtml#a254f5f6cb4ff37c2245b456b9bb79d2a)

ZOSAPI_Mode

**Definition:** Interfaces.cs:77