ResultsViewScenario: Integer;
ResultsViewScenario: integer;
The ResultsViewScenario property determines the key of the scenario, by which the model is calculated.
Set the value -1 in ResultsViewScenario to calculate by the Fact scenario.
Executing the example requires a form that contains the UiModel component with the UiModel1 identifier and the ModelBox component with the ModelBox1 identifier. UiModel1 is a data source for ModelBox1. Executing the example requires a modeling container with the MODEL_SPACE identifier, containing a modeling problem with the PROBLEM identifier. The modeling problem should contain several scenarios and calculate several models.
Add a link to the Metabase system assembly.
Sub UserProc;
Var
mb: IMetabase;
MsObj: IMetabaseObjectDescriptor;
ms: IMsModelSpace;
Problem: IMsProblem;
MetaModel: IMsMetaModel;
CalcChain: IMsCalculationChainEntries;
i: Integer;
CalcChainEntry: IMsCalculationChainEntry;
Scenarios: IMsProblemScenarios;
ScenKey: integer;
ScenTree: IMsScenarioTreeEntries;
ScenEntry: IMsScenarioTreeEntry;
Begin
UiModel1.Active := False;
mb := MetabaseClass.Active;
// Get modeling container
MsObj := mb.ItemById("MODEL_SPACE");
ms := MsObj.Bind As IMsModelSpace;
// Get modeling problem
Problem := mb.ItemByIdNamespace("PROBLEM", MsObj.Key).Bind As IMsProblem;
// Get metamodel calculated by the problem
MetaModel := Problem.MetaModel;
// Get metamodel calculation chain
CalcChain := MetaModel.CalculationChain;
// Get the first model in calculation chain
For i := 0 To CalcChain.Count - 1 Do
CalcChainEntry := CalcChain.Item(i);
If CalcChainEntry.Type = MsCalculationChainEntryType.Model Then
// Use the model as a data source for UiModel1
UiModel1.Model := (CalcChainEntry As IMsCalculationChainModel).Model;
UiModel1.Active := True;
Break;
End If;
End For;
// Get scenarios, by which modelling problem is calculated
Scenarios := Problem.Scenarios;
// Get the second scenario of modelling problem
ScenKey := Scenarios.Item(1).InternalKey;
// Get key of the second scenario
ScenTree := ms.ScenarioTree;
ScenEntry := ScenTree.FindByInternalKey(ScenKey);
// Specify that the model is calculated by the second scenario
ModelBox1.ResultsViewScenario := ScenEntry.Key;
// Calculate the model
ModelBox1.Execute;
// Save changes
ModelBox1.SaveObject;
End Sub UserProc;
Example execution result: The ModelBox1 component displays the first model calculated by the modeling problem; the second scenario of the modeling problem is used to calculate this model.
The requirements and result of the Fore.NET example execution match with those in the Fore example. Use Fore.NET analogs instead of Fore components.
Imports Prognoz.Platform.Interop.Ms;
…
Public Sub UserProc();
Var
mb: IMetabase;
MsObj: IMetabaseObjectDescriptor;
ms: IMsModelSpace;
Problem: IMsProblem;
MetaModel: IMsMetaModel;
CalcChain: IMsCalculationChainEntries;
i: Integer;
CalcChainEntry: IMsCalculationChainEntry;
Scenarios: IMsProblemScenarios;
ScenKey: uinteger;
ScenTree: IMsScenarioTreeEntries;
ScenEntry: IMsScenarioTreeEntry;
Begin
// uiModelNet1.Active := False;
mb := Self.Metabase;
// Get modeling container
MsObj := mb.ItemById["MODEL_SPACE"];
ms := MsObj.Bind() As IMsModelSpace;
// Get modeling problem
Problem := mb.ItemByIdNamespace["PROBLEM", MsObj.Key].Bind() As IMsProblem;
// Get metamodel calculated by the problem
MetaModel := Problem.MetaModel;
// Get metamodel calculation chain
CalcChain := MetaModel.CalculationChain;
// Get the first model in calculation chain
For i := 0 To CalcChain.Count - 1 Do
CalcChainEntry := CalcChain.Item[i];
If CalcChainEntry.Type = MsCalculationChainEntryType.mccetModel Then
// Use the model as a data source for uiModelNet1
uiModelNet1.Model := (CalcChainEntry As IMsCalculationChainModel).Model;
uiModelNet1.Active := True;
Break;
End If;
End For;
// Get scenarios, by which modelling problem is calculated
Scenarios := Problem.Scenarios;
// Get the second scenario of modelling problem
ScenKey := Scenarios.Item[1].InternalKey;
// Get key of the second scenario
ScenTree := ms.ScenarioTree;
ScenEntry := ScenTree.FindByInternalKey(ScenKey);
// Specify that the model is calculated by the second scenario
modelBoxNet1.CtrlBox.ResultsViewScenario := ScenEntry.Key;
// Calculate the model
modelBoxNet1.CtrlBox.Execute();
// Save changes
modelBoxNet1.CtrlBox.SaveObject();
End Sub;
See also: