GetFreeVariables: Array;
GetFreeVariables: System.Array;
The GetFreeVariables method returns the array of variables not participating in models.
Each element of the array is an object of the IMsFormulaTransformSlice interface.
Executing the example requires that the repository contains a modeling container with the MS identifier, containing a modeling problem with the MODEL_VAR_LVL identifier. This problem must contain the internal metamodel.
Add links to the Metabase, Ms system assemblies.
Sub GetFreeVars;
Var
mb: IMetabase;
MsObj: IMetabaseObjectDescriptor;
Problem: IMsProblem;
Meta: IMsMetaModel;
MetaVisual: IMsMetaModelVisualController;
i: Integer;
Transf: IMsFormulaTransform;
Series: IMsFormulaTransformVariables;
Data: Array Of Variant;
Begin
mb := MetabaseClass.Active;
// Get modeling container
MsObj := mb.ItemById("MS");
// Get modeling problem
Problem := mb.ItemByIdNamespace("MODEL_VAR_LVL", MsObj.Key).Bind As IMsProblem;
// Get metamodel
Meta := Problem.MetaModel;
MetaVisual := Meta.VisualController;
// Get all variables
MetaVisual.UpdateVariables;
Transf := MetaVisual.VariablesTransform;
Series := Transf.Series;
// Specify that variable names
//contain data source name
MetaVisual.UseSourceName := True;
// Display their names in the console window
Debug.WriteLine("All variables:");
For i := 0 To Series.Count - 1 Do
Debug.WriteLine(" - " + (Series.Item(i).Slices.Item(0).Name));
End For;
// Get free variables
Data := MetaVisual.GetFreeVariables;
// Display their names in the console window
Debug.WriteLine("");
Debug.WriteLine("Free variables:");
For i := 0 To Data.Length - 1 Do
Debug.WriteLine(" - " + (Data[i] As IMsFormulaTransformSlice).Name);
End For;
End Sub GetFreeVars;
Example execution result: names of all variables and names of variables, which are not participating in models, are displayed in the console window.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Ms;
…
Public Shared Sub Main(Params: StartParams);
Var
mb: IMetabase;
MsObj: IMetabaseObjectDescriptor;
Problem: IMsProblem;
Meta: IMsMetaModel;
MetaVisual: IMsMetaModelVisualController;
i: Integer;
Transf: IMsFormulaTransform;
Series: IMsFormulaTransformVariables;
Data: System.Array;
Begin
mb := Params.Metabase;
// Get modeling container
MsObj := mb.ItemById["MS"];
// Get modeling problem
Problem := mb.ItemByIdNamespace["MODEL_VAR_LVL", MsObj.Key].Bind() As IMsProblem;
// Get metamodel
Meta := Problem.MetaModel;
MetaVisual := Meta.VisualController;
// Get all variables
MetaVisual.UpdateVariables();
Transf := MetaVisual.VariablesTransform;
Series := Transf.Series;
// Specify that variable names
//contain data source name
MetaVisual.UseSourceName := True;
// Display their names in the console window
System.Diagnostics.Debug.WriteLine("All variables:");
For i := 0 To Series.Count - 1 Do
System.Diagnostics.Debug.WriteLine(" - " + (Series.Item[i].Slices.Item[0].Name));
End For;
// Get free variables
Data := MetaVisual.GetFreeVariables();
// Display their names in the console window
System.Diagnostics.Debug.WriteLine("");
System.Diagnostics.Debug.WriteLine("Free variables:");
For i := 0 To Data.Length - 1 Do
System.Diagnostics.Debug.WriteLine(" - " + (Data[i] As IMsFormulaTransformSlice).Name);
End For;
End Sub;
See also: