CSharpStandalone_12_Seq_SystemExplorer
Last update: 17.07.2025using System;
using ZOSAPI;
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
// Attempt to create a Standalone connection
if (TheApplication == null)
{
HandleError("An unknown connection error occurred!");
return;
}
// Check the connection status
{
return;
}
{
HandleError("User plugin was started in the wrong mode: expected Server, found " + TheApplication.Mode.ToString());
return;
}
// creates new directory
System.IO.Directory.CreateDirectory(strPath);
// Select 6 wavelengths using a Gaussian Quadrature algorithm
// Define fields using Paraxial Image Height
// Change field 1 to be X=1.0 and Y=2.0
field1.X = 1.0;
field1.Y = 2.0;
// Inserts paraxial lens so there will not be an error when using ParaxialImageHeight
TheSystem.SystemData.Aperture.ApertureValue = 10;
ZOSAPI.Editors.LDE.ISurfaceTypeSettings s1_type = s1.GetSurfaceTypeSettings(ZOSAPI.Editors.LDE.SurfaceType.Paraxial) as ZOSAPI.Editors.LDE.ISurfaceTypeSettings;
s1.ChangeType(s1_type);
s1.Thickness = 100;
// Change polarization axis reference to be Y
sysPol.Method = ZOSAPI.SystemData.PolarizationMethod.YAxisMethod;
// Add Corning catalog and remove Schott catalog
// Add Title and Notes
sysTitleNotes.Title = "Add here the title";
sysTitleNotes.Notes = "Add here the notes";
// As default Files choose: COATING.DAT, SCATTER_PROFILE.DAT, ABG_DATA.DAT
sysFiles.CoatingFile = "COATING.DAT";
sysFiles.ScatterProfile = "SCATTER_PROFILE.DAT";
sysFiles.ABgDataFile = "ABG_DATA.DAT";
TheSystem.SystemData.Files.ReloadFiles();
// Change Lens Units to Inches
sysUnits.LensUnits = ZOSAPI.SystemData.ZemaxSystemUnits.Inches;
String file = "\\API\\CS\\e12_seq_system_explorer.zos";
// Clean up
FinishStandaloneApplication(TheApplication);
}
{
// Note - TheApplication will close automatically when this application exits, so this isn't strictly necessary in most cases
if (TheApplication != null)
{
TheApplication.CloseApplication();
}
}
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);
}
}
}
Definition: ZemaxService.cs:198
IZOSAPI_Application CreateNewApplication()
Attempts to launch a new instance of Optic Studio in 'headless' mode. Note that although the Optic St...
Definition: ZemaxService.cs:863
All data for a Lens Data Editor surface. This interface can be accessed via the ILensDataEditor inter...
Definition: InterfacesLDE.cs:791
ISurfaceTypeSettings GetSurfaceTypeSettings(SurfaceType type)
Create the settings for the specified type. Use this method to specify any extra data required to cha...
bool ChangeType(ISurfaceTypeSettings settings)
Changes the current surface to the specified type. Use GetSurfaceTypeSettings to get the relevant set...
This interface is used for selecting any files required by a surface, and for changing surface types....
Definition: InterfacesLDE.cs:746
Represent a complete optical system. A IOpticalSystem corresponds to a single .ZMX file....
Definition: Interfaces.cs:690
void SaveAs(string fileName)
Saves the current system to the specified file. All future calls to Save will use the same file.
ISystemData SystemData
Data for configuring everything in the System Explorer.
Definition: Interfaces.cs:848
This interface contains all information about the current ZOS-API connection, as well as methods for ...
Definition: Interfaces.cs:264
bool IsValidLicenseForAPI
Gets a value indicating whether this the API is currently useable.
Definition: Interfaces.cs:290
ZOSAPI_Mode Mode
Gets the current connetion mode. Use this to check if Optic Studio is expecting a user operand / anal...
Definition: Interfaces.cs:309
LicenseStatusType LicenseStatus
Gets the license status. Note that this displays the license edition if successful,...
Definition: Interfaces.cs:283
void CloseApplication()
Shut down the Optic Studio process.
IOpticalSystem PrimarySystem
Gets the primary system. When Mode is ZOSAPI_Mode.Server, this will initially be an empty sequential ...
Definition: Interfaces.cs:331
string SamplesDir
Gets the full path for the current user's samples directory (in the My Documents\Zemax\Samples\ folde...
Definition: Interfaces.cs:508
System field data. This interface can be accessed via the IFields interface.
Definition: InterfacesSE.cs:975
System Explorer - Fields Data. This interface can be accessed via the ISystemData interface.
Definition: InterfacesSE.cs:817
void SetFieldType(FieldType type)
Sets the field type definition for all fields.
System Explorer - Files Data. This interface can be accessed via the ISystemData interface.
Definition: InterfacesSE.cs:588
System Explorer - Material Catalogs Data. This interface can be accessed via the ISystemData interfac...
Definition: InterfacesSE.cs:500
bool RemoveCatalog(string catalog)
Removes the specified material catalog from the system.
bool AddCatalog(string catalog)
Adds the specified material to the system.
System Explorer - Polarization Data. This interface can be accessed via the ISystemData interface.
Definition: InterfacesSE.cs:438
System Explorer - Notes Data. This interface can be accessed via the ISystemData interface.
Definition: InterfacesSE.cs:562
System Explorer - Units Data. This interface can be accessed via the ISystemData interface.
Definition: InterfacesSE.cs:620
System Explorer - Wavelengths Data. This interface can be accessed via the ISystemData interface.
Definition: InterfacesSE.cs:649
bool GaussianQuadrature(double minWave, double maxWave, QuadratureSteps numSteps)
Generates a new set of system wavelengths based on a Gaussian Quadrature method.
Definition: InterfacesLDE.cs:8
Definition: InterfacesEditors.cs:12
Definition: InterfacesSE.cs:11
The ZOSAPI namespace contains classes for initially connecting to zemax. See also ZOSAPI_Connection,...
Definition: IAS_FieldCurvatureAndDistortion.cs:5