IMsBranchConditionNotEmpty.SetStub

Syntax

SetStub(pStub: IVariableStub);

Parameters

pStub. A data source containing a series checked for emptiness.

Description

The SetStub method sets a data source that contains a series checked for emptiness.

Comments

To get a slice that corresponds to the checked series, use the IMsBranchConditionNotEmpty.Slice property.

Example

Executing the example requires that the repository contains a modeling container with the MS identifier. This container should contain a metamodel with the METAMODEL_BRANCH identifier and models with the MODEL_LINEAR and MODEL_TSLS identifiers.

Add links to the Metabase, Ms system assemblies.

Sub UserProc;
Var
    mb: IMetabase;
    MsKey: Integer;
    MetaModel: IMsMetaModel;
    Chain, DefaultContents: IMsCalculationChainEntries;
    Branch: IMsCalculationChainBranch;
    Case_1, Case_default: IMsModel;
    CaseList: IMsBranchCaseList;
    CaseItem: IMsBranchCase;
    BranchConditions: IMsBranchConditions;
    ConditionNotEmpty: IMsBranchConditionNotEmpty;
    Transform: IMsFormulaTransform;
    Output: IMsFormulaTransformVariable;
    Slice: IMsFormulaTransformSlice;
Begin
    // Get current repository
    mb := MetabaseClass.Active;
    // Get modeling container
    MsKey := mb.GetObjectKeyById("MS");
    // Get metamodel
    MetaModel := mb.ItemByIdNamespace("METAMODEL_BRANCH", MsKey).Edit As IMsMetaModel;
    // Get metamodel calculation chain
    Chain := MetaModel.CalculationChain;
    // Clear metamodel calculation chain
    Chain.Clear;
    // Create a condition node
    Branch := Chain.AddBranch("Condition");
    // Get default calculation chain that is calculated
    // if none of condition branches is executed
    DefaultContents := Branch.DefaultContents;
    // Get the MODEL_LINEAR model
    Case_default := mb.ItemByIdNamespace("MODEL_LINEAR", MsKey).Bind As IMsModel;
    // Add the MODEL_LINEAR model to default calculation chain
    DefaultContents.AddModel(Case_default);
    // Get condition branches collection
    CaseList := Branch.CaseList;
    // Add a condition branch
    CaseItem := CaseList.Add;
    // Get the MODEL_TSLS model
    Case_1 := mb.ItemByIdNamespace("MODEL_TSLS", MsKey).Bind As IMsModel;
    // Specify that this model must be calculated if this condition branch is executed
    CaseItem.Contents.AddModel(Case_1);
    // Get collection of branch calculation conditions
    BranchConditions := CaseItem.Conditions;
    // Add a branch calculation condition: specified series must contain data
    ConditionNotEmpty := BranchConditions.Add(MsBranchConditionType.NotEmpty) As IMsBranchConditionNotEmpty;
    // Get output variable in the MODEL_TSLS model
    Transform := Case_1.Transform;
    Output := Transform.Outputs.Item(0);
    // Specify that data source of output variable
    // contains a series checked for data presence
    ConditionNotEmpty.SetStub(Output.VariableStub);
    // Get data slice that corresponds to the series that will be checked for data presence
    Slice := ConditionNotEmpty.Slice;
    // Set selection identical to output variable selection
    Slice.Selection := Output.Slices.Item(0).Selection;
    // Save changes
    (MetaModel As IMetabaseObject).Save;
End Sub UserProc;

After executing the example a condition is created in the metamodel calculation chain: if output variable of the MODEL_TSLS model is not empty, this model is calculated, otherwise the MODEL_LINEAR model is calculated.

See also:

IMsBranchConditionNotEmpty