Skip to main content

Zemax OpticStudio ZOS-API 2026 R1

Interface ZOSAPI::Editors::MFE::IMeritFunctionEditor

Last update: 13.03.2026

Definition:

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

Inherits from:

Members

Properties

Property RowToOperandOffset

Definition:

int ZOSAPI.Editors.MFE.IMeritFunctionEditor.RowToOperandOffset

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

The row to operand offset.

Return type: int

Property NumberOfOperands

Definition:

int ZOSAPI.Editors.MFE.IMeritFunctionEditor.NumberOfOperands

Gets the total number of operands in the current system.

The number of operands.

Return type: int

Property FirstColumn

Definition:

MeritColumn ZOSAPI.Editors.MFE.IMeritFunctionEditor.FirstColumn

Gets the first available column.

The first column.

Return type: MeritColumn

Property LastColumn

Definition:

MeritColumn ZOSAPI.Editors.MFE.IMeritFunctionEditor.LastColumn

Gets the last available column.

The last column.

Return type: MeritColumn

Property MeritFunctionDirectory

Definition:

string ZOSAPI.Editors.MFE.IMeritFunctionEditor.MeritFunctionDirectory

Gets the default merit function directory.

The merit function directory.

Return type: string

Property NSCOptimizationWizard

Definition:

INSCOptimizationWizard ZOSAPI.Editors.MFE.IMeritFunctionEditor.NSCOptimizationWizard

Get the Nonsequential Optimization Wizard.

Returns:

Return type: INSCOptimizationWizard

Property SEQOptimizationWizard

Definition:

ISEQOptimizationWizard ZOSAPI.Editors.MFE.IMeritFunctionEditor.SEQOptimizationWizard

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;
            ISEQOptimizationWizard 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();
            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");

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:

Return type: ISEQOptimizationWizard

Property NSCBitmapWizard

Definition:

INSCBitmapWizard ZOSAPI.Editors.MFE.IMeritFunctionEditor.NSCBitmapWizard

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

Returns:

Return type: INSCBitmapWizard

Property NSCRoadwayLightingWizard

Definition:

INSCRoadwayLightingWizard ZOSAPI.Editors.MFE.IMeritFunctionEditor.NSCRoadwayLightingWizard

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

Returns:

Return type: INSCRoadwayLightingWizard

Property SEQOptimizationWizard2

Definition:

ISEQOptimizationWizard2 ZOSAPI.Editors.MFE.IMeritFunctionEditor.SEQOptimizationWizard2

Get the latest Sequential Optimization Wizard.

Return type: ISEQOptimizationWizard2

Public functions

Function GetOperandAt

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

Gets the data for the specified operand.

Parameters:

  • OperandNumber: The operand number (1 to NumberOfOperands).

Returns:

Parameters:

  • int OperandNumber

Return type: IMFERow

Function InsertNewOperandAt

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

Inserts a new operand at the specified position.

Parameters:

  • OperandNumber: The operand number (1 to NumberOfOperands+1).

Returns:

Parameters:

  • int OperandNumber

Return type: IMFERow

Function AddOperand

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

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

Returns:

Return type: IMFERow

Function RemoveOperandAt

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

Removes the operand at the specified location.

Parameters:

  • OperandNumber: The operand number (1 to NumberOfOperands).

Returns:

true if the operand was successfully remove; otherwise, false.

Parameters:

  • int OperandNumber

Return type: bool

Function RemoveOperandsAt

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

Removes one or more operands at the specified location.

Parameters:

  • OperandNumber: The first operand number to remove (1 to NumberOfOperands).
  • numOperands: The number operands to remove.

Returns:

The number of operands actually removed.

Parameters:

  • int OperandNumber
  • int numOperands

Return type: int

Function 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:

Return type: bool

Function 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:

Return type: void

Function SaveMeritFunction

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

Saves the entire merit function to the specified file.

Parameters:

  • fileName: Name of the file.

Parameters:

  • string fileName

Return type: void

Function LoadMeritFunction

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

Replaces the entire MFE with the specified file contents.

Parameters:

  • fileName: Name of the file.

Parameters:

  • string fileName

Return type: void

Function 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:

  • fileName: Name of the file.
  • OperandNumber: The position to insert the merit function at (1 to NumberOfOperands+1).

Returns:

Parameters:

  • string fileName
  • int OperandNumber

Return type: int

Function GetMeritFunctionFiles

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

Gets the merit function files in the default directory.

Returns:

Return type: string[]

Function 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:

Return type: double

Function 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:

  • type: type of operand
  • srf: surface / integer parameter 1
  • wave: wavelength / integer parameter 2
  • Hx: hx / double parameter 1
  • Hy: hy / double parameter 2
  • Px: px / double parameter 3
  • Py: py / double parameter 4
  • Ex: Ex / double parameter 5
  • Ey: Ey / double parameter 6

Returns:

The computed value of the specified operand

Parameters:

  • MeritOperandType type
  • int srf
  • int wave
  • double Hx
  • double Hy
  • double Px
  • double Py
  • double Ex
  • double Ey

Return type: double

Function 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:

  • fromOperandNumber: First operand number to copy (1 to NumberOfOperands).
  • NumberOfOperands: The number of operands to copy.
  • toOperandNumber: Row to start inserting the operands (1 to NumberOfOperands+1).

Returns:

The number of operands actually copied.

Parameters:

  • int fromOperandNumber
  • int NumberOfOperands
  • int toOperandNumber

Return type: int

Function 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:

  • fromEditor: System to copy the operands from.
  • fromOperandNumber: First operand number to copy (1 to NumberOfOperands).
  • NumberOfOperands: The number of operands to copy.
  • toOperandNumber: To operand number (1 to NumberOfOperands+1).

Returns:

The number of operands actually copied.

Parameters:

Return type: int

Connect with Ansys