Skip to main content

ZOS-API interface 2024 R1

ZOSAPI.Editors.MFE.IMeritFunctionEditor Interface Reference

Last update: 17.07.2025

This interface defines all properties and methods needed to interact with the MRit Function Editor. This interface can be accessed via the IOpticalSystem interface. More...

Inheritance diagram for ZOSAPI.Editors.MFE.IMeritFunctionEditor:

Public Member Functions

IMFERow GetOperandAt (int OperandNumber)
 Gets the data for the specified operand.
 
IMFERow InsertNewOperandAt (int OperandNumber)
 Inserts a new operand at the specified position.
 
IMFERow AddOperand ()
 Adds a new operand as the last operand in the system.
 
bool RemoveOperandAt (int OperandNumber)
 Removes the operand at the specified location.
 
int RemoveOperandsAt (int OperandNumber, int numOperands)
 Removes one or more operands at the specified location.
 
bool ShowMFE ()
 Shows this editor in the UI. Note that this only has an effect if the IOpticalSystem.Mode is ZOSAPI_Mode.Plugin.
 
void HideMFE ()
 Closes this editor in the UI. Note that this only has an effect if the IOpticalSystem.Mode is ZOSAPI_Mode.Plugin.
 
void SaveMeritFunction (string fileName)
 Saves the entire merit function to the specified file.
 
void LoadMeritFunction (string fileName)
 Replaces the entire MFE with the specified file contents.
 
int InsertMeritFunction (string fileName, int OperandNumber)
 Loads a merit function from the file and inserts it at the specified location.
 
string[] GetMeritFunctionFiles ()
 Gets the merit function files in the default directory.
 
double CalculateMeritFunction ()
 Calculates the current value of the merit function. Note that this method is not asynchronous, and may take a long time to calculate in some cases.
 
double GetOperandValue (MeritOperandType type, int srf, int wave, double Hx, double Hy, double Px, double Py, double Ex, double Ey)
 Returns the value of any optimization operand, even if the operand is not currently in the merit function.
 
int CopyOperands (int fromOperandNumber, int NumberOfOperands, int toOperandNumber)
 Copy and paste the specified number of operands from one location to another.
Note that it is okay for the source and destination to overlap.
 
int CopyOperandsFrom (IMeritFunctionEditor fromEditor, int fromOperandNumber, int NumberOfOperands, int toOperandNumber)
 Copy and paste the specified number of operands from one location (in the specified system) to another location (in this system). Note that it is okay for the source and destination to overlap.
 
- Public Member Functions inherited from ZOSAPI.Editors.IEditor
IEditorRow GetRowAt (int pos)
 Gets the row at the specified index (0 to NumberOfRows-1).
 
IEditorRow InsertRowAt (int pos)
 Inserts a new row at the specified index (0 to NumberOfRows). Note that some editors - such as the Lens Data Editor may not allow inserting new rows before the first row.
 
IEditorRow AddRow ()
 Adds a new row at the end of the editor.
 
bool DeleteRowAt (int pos)
 Deletes a row at the specified index (0 to NumberOfRows-1). Note that all editors require at least one row, and some editors may require more than that.
 
int DeleteRowsAt (int pos, int numberOfRows)
 Deletes one or more rows at the specified index (0 to NumberOfRows-1).
 
int DeleteAllRows ()
 Deletes all rows from the current editor.
 
bool ShowEditor ()
 Shows this editor in the UI. Note that this only has an effect if the IOpticalSystem.Mode is ZOSAPI_Mode.Plugin.
 
void HideEditor ()
 Closes this editor in the UI. Note that this only has an effect if the IOpticalSystem.Mode is ZOSAPI_Mode.Plugin.
 

Properties

int RowToOperandOffset [get]
 Offset from a row index to operand index (always 1).
 
int NumberOfOperands [get]
 Gets the total number of operands in the current system.
 
MeritColumn FirstColumn [get]
 Gets the first available column.
 
MeritColumn LastColumn [get]
 Gets the last available column.
 
string MeritFunctionDirectory [get]
 Gets the default merit function directory.
 
INSCOptimizationWizard NSCOptimizationWizard [get]
 Get the Nonsequential Optimization Wizard.
 
ISEQOptimizationWizard SEQOptimizationWizard [get]
 Get the Sequential Optimization Wizard; note that this wizard is obsolete and you should use SEQOptimizationWizard2 instead.
 
INSCBitmapWizard NSCBitmapWizard [get]
 Get the Mode-appropriate (Nonsequential/Sequential) Bitmap Wizard, Nonsequential ONLY.
 
INSCRoadwayLightingWizard NSCRoadwayLightingWizard [get]
 Get the Mode-appropriate (Nonsequential/Sequential) Roadway Lighting Wizard, Nonsequential ONLY.
 
ISEQOptimizationWizard2 SEQOptimizationWizard2 [get]
 Get the latest Sequential Optimization Wizard.
 
- Properties inherited from ZOSAPI.Editors.IEditor
EditorType Editor [get]
 Gets the type of this editor instance.
 
int NumberOfRows [get]
 Gets the number of rows in this editor. Note that this referes to surfaces, objects, or operands depending on editor type.
 
int MinColumn [get]
 The minimum column index that can be used in calls to IEditorRow.GetCellAt for any IEditorRow retrieved from this editor.
 
int MaxColumn [get]
 The maximum column index that can be used in calls to IEditorRow.GetCellAt for any IEditorRow retrieved from this editor.
 

Detailed Description

This interface defines all properties and methods needed to interact with the MRit Function Editor. This interface can be accessed via the IOpticalSystem interface.

Examples
CSharpStandalone_03_open_file_and_optimise.cs, and CSharpStandalone_15_Seq_Optimization.cs.

Member Function Documentation

◆ AddOperand()

IMFERow ZOSAPI.Editors.MFE.IMeritFunctionEditor.AddOperand ( )

Adds a new operand as the last operand in the system.

Returns
Examples
CSharpStandalone_03_open_file_and_optimise.cs.

◆ CalculateMeritFunction()

double ZOSAPI.Editors.MFE.IMeritFunctionEditor.CalculateMeritFunction ( )

Calculates the current value of the merit function. Note that this method is not asynchronous, and may take a long time to calculate in some cases.

Returns

◆ CopyOperands()

int ZOSAPI.Editors.MFE.IMeritFunctionEditor.CopyOperands ( int  fromOperandNumber,
int  NumberOfOperands,
int  toOperandNumber 
)

Copy and paste the specified number of operands from one location to another.
Note that it is okay for the source and destination to overlap.

Parameters
fromOperandNumberFirst operand number to copy (1 to NumberOfOperands).
NumberOfOperandsThe number of operands to copy.
toOperandNumberRow to start inserting the operands (1 to NumberOfOperands+1).
Returns
The number of operands actually copied.

◆ CopyOperandsFrom()

int ZOSAPI.Editors.MFE.IMeritFunctionEditor.CopyOperandsFrom ( IMeritFunctionEditor  fromEditor,
int  fromOperandNumber,
int  NumberOfOperands,
int  toOperandNumber 
)

Copy and paste the specified number of operands from one location (in the specified system) to another location (in this system). Note that it is okay for the source and destination to overlap.

Parameters
fromEditorSystem to copy the operands from.
fromOperandNumberFirst operand number to copy (1 to NumberOfOperands).
NumberOfOperandsThe number of operands to copy.
toOperandNumberTo operand number (1 to NumberOfOperands+1).
Returns
The number of operands actually copied.

◆ GetMeritFunctionFiles()

string[] ZOSAPI.Editors.MFE.IMeritFunctionEditor.GetMeritFunctionFiles ( )

Gets the merit function files in the default directory.

Returns

◆ GetOperandAt()

IMFERow ZOSAPI.Editors.MFE.IMeritFunctionEditor.GetOperandAt ( int  OperandNumber)

Gets the data for the specified operand.

Parameters
OperandNumberThe operand number (1 to NumberOfOperands).
Returns
Examples
CSharpStandalone_03_open_file_and_optimise.cs.

◆ GetOperandValue()

double ZOSAPI.Editors.MFE.IMeritFunctionEditor.GetOperandValue ( MeritOperandType  type,
int  srf,
int  wave,
double  Hx,
double  Hy,
double  Px,
double  Py,
double  Ex,
double  Ey 
)

Returns the value of any optimization operand, even if the operand is not currently in the merit function.

Parameters
typetype of operand
srfsurface / integer parameter 1
wavewavelength / integer parameter 2
Hxhx / double parameter 1
Hyhy / double parameter 2
Pxpx / double parameter 3
Pypy / double parameter 4
ExEx / double parameter 5
EyEy / double parameter 6
Returns
The computed value of the specified operand

◆ HideMFE()

void ZOSAPI.Editors.MFE.IMeritFunctionEditor.HideMFE ( )

Closes this editor in the UI. Note that this only has an effect if the IOpticalSystem.Mode is ZOSAPI_Mode.Plugin.

Returns

◆ InsertMeritFunction()

int ZOSAPI.Editors.MFE.IMeritFunctionEditor.InsertMeritFunction ( string  fileName,
int  OperandNumber 
)

Loads a merit function from the file and inserts it at the specified location.

Parameters
fileNameName of the file.
OperandNumberThe position to insert the merit function at (1 to NumberOfOperands+1).
Returns

◆ InsertNewOperandAt()

IMFERow ZOSAPI.Editors.MFE.IMeritFunctionEditor.InsertNewOperandAt ( int  OperandNumber)

Inserts a new operand at the specified position.

Parameters
OperandNumberThe operand number (1 to NumberOfOperands+1).
Returns
Examples
CSharpStandalone_03_open_file_and_optimise.cs.

◆ LoadMeritFunction()

void ZOSAPI.Editors.MFE.IMeritFunctionEditor.LoadMeritFunction ( string  fileName)

Replaces the entire MFE with the specified file contents.

Parameters
fileNameName of the file.
Examples
CSharpStandalone_15_Seq_Optimization.cs.

◆ RemoveOperandAt()

bool ZOSAPI.Editors.MFE.IMeritFunctionEditor.RemoveOperandAt ( int  OperandNumber)

Removes the operand at the specified location.

Parameters
OperandNumberThe operand number (1 to NumberOfOperands).
Returns
true if the operand was successfully remove; otherwise, false.

◆ RemoveOperandsAt()

int ZOSAPI.Editors.MFE.IMeritFunctionEditor.RemoveOperandsAt ( int  OperandNumber,
int  numOperands 
)

Removes one or more operands at the specified location.

Parameters
OperandNumberThe first operand number to remove (1 to NumberOfOperands).
numOperandsThe number operands to remove.
Returns
The number of operands actually removed.

◆ SaveMeritFunction()

void ZOSAPI.Editors.MFE.IMeritFunctionEditor.SaveMeritFunction ( string  fileName)

Saves the entire merit function to the specified file.

Parameters
fileNameName of the file.
Examples
CSharpStandalone_15_Seq_Optimization.cs.

◆ ShowMFE()

bool ZOSAPI.Editors.MFE.IMeritFunctionEditor.ShowMFE ( )

Shows this editor in the UI. Note that this only has an effect if the IOpticalSystem.Mode is ZOSAPI_Mode.Plugin.

Returns

Property Documentation

◆ FirstColumn

MeritColumn ZOSAPI.Editors.MFE.IMeritFunctionEditor.FirstColumn
get

Gets the first available column.

The first column.

◆ LastColumn

MeritColumn ZOSAPI.Editors.MFE.IMeritFunctionEditor.LastColumn
get

Gets the last available column.

The last column.

◆ MeritFunctionDirectory

string ZOSAPI.Editors.MFE.IMeritFunctionEditor.MeritFunctionDirectory
get

Gets the default merit function directory.

The merit function directory.

◆ NSCBitmapWizard

INSCBitmapWizard ZOSAPI.Editors.MFE.IMeritFunctionEditor.NSCBitmapWizard
get

Get the Mode-appropriate (Nonsequential/Sequential) Bitmap Wizard, Nonsequential ONLY.

Returns

◆ NSCOptimizationWizard

INSCOptimizationWizard ZOSAPI.Editors.MFE.IMeritFunctionEditor.NSCOptimizationWizard
get

Get the Nonsequential Optimization Wizard.

Returns

◆ NSCRoadwayLightingWizard

INSCRoadwayLightingWizard ZOSAPI.Editors.MFE.IMeritFunctionEditor.NSCRoadwayLightingWizard
get

Get the Mode-appropriate (Nonsequential/Sequential) Roadway Lighting Wizard, Nonsequential ONLY.

Returns

◆ NumberOfOperands

int ZOSAPI.Editors.MFE.IMeritFunctionEditor.NumberOfOperands
get

Gets the total number of operands in the current system.

The number of operands.

◆ RowToOperandOffset

int ZOSAPI.Editors.MFE.IMeritFunctionEditor.RowToOperandOffset
get

Offset from a row index to operand index (always 1).

The row to operand offset.

◆ SEQOptimizationWizard

ISEQOptimizationWizard ZOSAPI.Editors.MFE.IMeritFunctionEditor.SEQOptimizationWizard
get

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

Usage (see Example 15 for a full sample)

C#

//define merit function
//load merit function
IMeritFunctionEditor TheMFE = TheSystem.MFE;
//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 & 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();
string mf_filename = System.IO.Path.Combine(TheApplication.SamplesDir, @"API\CS\e15_Seq_Optimization\RMS_Spot_Radius.mf");
TheMFE.SaveMeritFunction(mf_filename);
TheMFE.LoadMeritFunction(mf_filename);
SampleFile = System.IO.Path.Combine(TheApplication.SamplesDir, @"API\CS\e15_Seq_Optimization\OptimizedFile4.zos");
This interface defines all properties and methods needed to interact with the MRit Function Editor....
Definition: InterfacesMFE.cs:491
void LoadMeritFunction(string fileName)
Replaces the entire MFE with the specified file contents.
ISEQOptimizationWizard SEQOptimizationWizard
Get the Sequential Optimization Wizard; note that this wizard is obsolete and you should use SEQOptim...
Definition: InterfacesMFE.cs:647
void SaveMeritFunction(string fileName)
Saves the entire merit function to the specified file.
Interface for the Merit Function, Sequential Optimization Wizard These settings can be retrieved from...
Definition: InterfacesWizards.cs:293

C++

// define merit function
// load merit function
IMeritFunctionEditorPtr TheMFE = TheSystem->MFE;
// need to ensure that you have the Platform set as x64 and not Win32
ISEQOptimizationWizardPtr OptWizard = TheMFE->SEQOptimizationWizard;
// 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 & 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!
IWizardPtr baseToolWiz = OptWizard;
baseToolWiz->Apply();
_bstr_t mf_filename = _bstr_t(TheApplication->SamplesDir + "\\API\\CPP\\e15_Seq_Optimization\\RMS_Spot_Radius.mf");
TheMFE->SaveMeritFunction(mf_filename);
TheMFE->LoadMeritFunction(mf_filename);
SampleFile = _bstr_t(TheApplication->SamplesDir + "\\API\\CPP\\e15_Seq_Optimization\\OptimizedFile4.zos");
TheSystem->SaveAs(SampleFile);

Matlab

%define merit function
%load merit function
TheMFE = TheSystem.MFE;
OptWizard = TheMFE.SEQOptimizationWizard;
%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 & 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();
mf_filename = System.String.Concat(TheApplication.SamplesDir, '\API\Matlab\e15_Seq_Optimization\RMS_Spot_Radius.mf');
TheMFE.SaveMeritFunction(mf_filename);
TheMFE.LoadMeritFunction(mf_filename);
SampleFile = System.String.Concat(TheApplication.SamplesDir, '\API\Matlab\e15_Seq_Optimization\OptimizedFile4.zos');

Python

# define merit function
# load merit function
# you need to have 64-bit pywin32 to use the SEQOptimizationWizard with an error
TheMFE = TheSystem.MFE
OptWizard = TheMFE.SEQOptimizationWizard
# 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 & 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()
mf_filename = TheApplication.SamplesDir + '\\API\\Python\\e15_Seq_Optimization\\RMS_Spot_Radius.mf'
TheMFE.SaveMeritFunction(mf_filename)
TheMFE.LoadMeritFunction(mf_filename)
SampleFile = TheApplication.SamplesDir + '\\API\\Python\\e15_Seq_Optimization\\OptimizedFile4.zos'
TheSystem.SaveAs(SampleFile)
Returns
Examples
CSharpStandalone_15_Seq_Optimization.cs.

◆ SEQOptimizationWizard2

ISEQOptimizationWizard2 ZOSAPI.Editors.MFE.IMeritFunctionEditor.SEQOptimizationWizard2
get

Get the latest Sequential Optimization Wizard.

Connect with Ansys