GetDimInstance(DimModel: IMetabaseObjectDescriptor, Stub: IVariableStub): IDimInstance;
DimModel. Dictionary used in abstract data source.
Stub. Abstract data source.
The GetDimInstance method returns dictionary data from the abstract data source.
The method is relevant to get dictionary data is used on modeling problem calculation taking into account controlling dimensions in a cube.
An abstract data source can be:
Standard cube.
Virtual cube.
Cube view.
Time series database.
Modeling variable that is a separate repository object.
To get abstract data source, cast the required object to the IVariableStub interface.
Executing the example requires that the repository contains a modeling container with the CONT_MODEL identifier that contains a modeling problem with the PROBLEM identifier and a metamodel. The metamodel should have a calculation chain, which uses a standard cube with the CUBE identifier with a controlling dimension, and a parameter of the Selection type. As a controlling dimension and a parameter for metamodel, a parametric table MDM dictionary with the DIMENSION_PARAM identifier is used.
Add links to the Metabase, Ms, Cubes, Dimensions system assemblies.
Sub UserProc;
Var
Mb: IMetabase;
MsKey, i: Integer;
Problem: IMsProblem;
MetaModel: IMsMetaModel;
Stub: IVariableStub;
ParamDim: IMetabaseObjectDescriptor;
DimInst: IDimInstance;
Elements: IDimElements;
DimSelect: IDimSelection;
Name: String;
Settings: IMsProblemCalculationSettings;
Calc: IMsProblemCalculation;
ParamValues: IMsModelParamValues;
Begin
// Get the current repository
Mb := MetabaseClass.Active;
// Get modeling container key
MsKey := Mb.GetObjectKeyById("CONT_MODEL");
// Get modeling problem
Problem := Mb.ItemByIdNamespace("PROBLEM", MsKey).Edit As IMsProblem;
// Get metamodel
MetaModel := Problem.MetaModel;
// Get abstract data source (cube) and dictionary data
Stub := Mb.ItemById("CUBE").Bind As IVariableStub;
ParamDim := Mb.ItemById("DIMENSION_PARAM");
DimInst := MetaModel.GetDimInstance(ParamDim, Stub);
// Display names of obtained dictionary elements in the console
Elements := DimInst.Elements;
For i := 0 To Elements.Count - 1 Do
Name := Elements.Name(i);
Debug.WriteLine(Name);
End For;
// Determine modeling problem calculation settings
Settings := Problem.CreateCalculationSettings;
// Get metamodel parameter and set selection from obtained dictionary elements
ParamValues := Settings.ParamValues;
DimSelect := DimInst.CreateSelection;
DimSelect.SelectElement(1, False);
DimSelect.SelectElement(3, False);
ParamValues.Item(0).Value := DimSelect;
Calc := Problem.Calculate(Settings);
// Calculate modeling problem
Calc.Run;
End Sub UserProc;
Imports Prognoz.Platform.Interop.Metabase;
Imports Prognoz.Platform.Interop.Ms;
Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Dimensions;
…
Public Shared Sub Main(Params: StartParams);
Var
Mb: IMetabase;
MsKey, i: UInteger;
Problem: IMsProblem;
MetaModel: IMsMetaModel;
Stub: IVariableStub;
ParamDim: IMetabaseObjectDescriptor;
DimInst: IDimInstance;
Elements: IDimElements;
DimSelect: IDimSelection;
Name: String;
Settings: IMsProblemCalculationSettings;
Calc: IMsProblemCalculation;
ParamValues: IMsModelParamValues;
Begin
// Get the current repository
Mb := Params.Metabase;
// Get modeling container key
MsKey := Mb.GetObjectKeyById("CONT_MODEL");
// Get modeling problem
Problem := Mb.ItemByIdNamespace["PROBLEM", MsKey].Edit() As IMsProblem;
// Get metamodel
MetaModel := Problem.MetaModel;
// Get abstract data source (cube) and dictionary data
Stub := Mb.ItemById["CUBE"].Bind() As IVariableStub;
ParamDim := Mb.ItemById["DIMENSION_PARAM"];
DimInst := MetaModel.GetDimInstance(ParamDim, Stub);
// Display names of obtained dictionary elements in the console
Elements := DimInst.Elements;
For i := 0 To Elements.Count - 1 Do
Name := Elements.Name[i];
System.Diagnostics.Debug.WriteLine(Name);
End For;
// Determine modeling problem calculation settings
Settings := Problem.CreateCalculationSettings();
// Get metamodel parameter and set selection from obtained dictionary elements
ParamValues := Settings.ParamValues;
DimSelect := DimInst.CreateSelection();
DimSelect.SelectElement(1, False);
DimSelect.SelectElement(3, False);
ParamValues.Item[0].Value := DimSelect;
Calc := Problem.Calculate(Settings);
// Calculate modeling problem
Calc.Run();
End Sub;
After executing the example, dictionary data is obtained from the abstract data source, and the modeling problem is calculated with the specified selection in the metamodel parameter from obtained dictionary elements with the 1 and 3 indexes. The console displays names of all dictionary elements.
See also: