IDimSelectionSet.Add

Syntax

Add(DimInstance: IDimInstance): IDimSelection;

Parameters

DimInstance. The dictionary selection of which is to be added.

Description

The Add method adds dictionary to collection and returns its selection.

Example

Executing the example requires a modeling container with two variables that have additional dimensions.

Sub Main;

Var

MB: IMetabase;

CrInf: IMetabaseObjectCreateInfo;

MObj: IMetabaseObject;

Model: IMsModel;

Trans: IMsFormulaTransform;

VarTrans: IMsFormulaTransformVariable;

Slice, Slice1: IMsFormulaTransformSlice;

Selector: IMsFormulaTransformSelector;

Formula: IMsFormula;

NonLinear: IMsNonLinearRegressionTransform;

Varr: IMsVariable;

TransVar: IMsFormulaTransformVariable;

TermX1, TermX2: IMsFormulaTerm;

SelectionFact: IDimSelectionSetFactory;

Selection: IDimSelectionSet;

s: String;

i: Integer;

Begin

MB := MetabaseClass.Active;

//create model

CrInf := Mb.CreateCreateInfo;

CrInf.ClassId := MetabaseObjectClass.KE_CLASS_MSMODEL;

CrInf.Id := "New_NonLinReg";

CrInf.Name := "New_NonLinReg";

CrInf.Parent := Mb.ItemById("KONT_MODEL");

MObj := Mb.CreateObject(CrInf).Edit;

Model := MObj As IMsModel;

Trans := Model.Transform;

// add modeled variable

Varr := MB.ItemByIdNamespace("Var_1", MB.ItemById("KONT_MODEL").Key).Bind As IMsVariable;

Model.Output.Add(Varr);

//create empty selection

SelectionFact := New DimSelectionSetFactory.Create;

Selection := SelectionFact.CreateDimSelectionSet;

//if the output variable has additional dimensions, select element with the index 3

For i := 0 To Varr.Dimensions.Count - 1 Do

Selection.Add((Varr.Dimensions.Item(i).Model As IMetabaseObject).Open(Null) As IDimInstance);

Selection.Item(i).SelectElement(3, False);

End For;

VarTrans := Trans.Outputs.Item(0);

//get slice in output variable

Slice := VarTrans.Slices.Add(Selection);

Selector := Model.Transform.CreateSelector;

Selector.Slice := Slice;

Formula := Model.Transform.Transform(Selector);

Formula.Kind := MsFormulaKind.NonLinearRegression;

NonLinear := Formula.Method As IMsNonLinearRegressionTransform;

//add input variable

Varr := MB.ItemByIdNamespace("Var_Factor", MB.ItemById("KONT_MODEL").Key).Bind As IMsVariable;

Model.Input.Add(Varr);

TransVar := Model.Transform.Inputs.Item(0);

//fix selection in all additional dimensions

For i := 0 To Varr.Dimensions.Count - 1 Do

Selection.Add((Varr.Dimensions.Item(i).Model As IMetabaseObject).Open(Null) As IDimInstance);

Selection.Item(i).DeselectAll;

Selection.Item(i).SelectElement(1, False);

End For;

//add slice to variable

Slice := TransVar.Slices.Add(Selection);

//create selection for the second slice

For i := 0 To Varr.Dimensions.Count - 1 Do

Selection.Item(i).DeselectAll;

Selection.Item(i).SelectElement(3, False);

End For;

//add the second slice to the variable

Slice1 := TransVar.Slices.Add(Selection);

//create two terms based on different variable slices

TermX1 := NonLinear.Operands.Add(Slice);

TermX2 := NonLinear.Operands.Add(Slice1);

//create equation

s := "A0+" + Trans.SliceToTerm(TermX1.Slice, TermX1.Lag.AsString) + "/10+ " + Trans.SliceToTerm(TermX2.Slice, TermX2.Lag.AsString);

NonLinear.Expression.AsString := s;

MObj.Save;

End Sub Main;

After executing the example a model is created in modeling container. An output variable is added to the model; elements with the index 3 are selected in all additional dimensions of this variable. Calculation specification is set up for the obtained slice. Non-linear regression method is used in calculations. A variable with some elements fixed in additional dimensions is added to the list of input variables. Then terms are obtained and an equation is formed.

See also:

IDimSelectionSet