Add: ITsModelParam;
The Add method adds a parameter to the collection.
To remove a specific parameter from the collection, use the ITsModelParams.Remove and ITsModelParams.RemoveByKey methods, and to remove all parameters, use the ITsModelParams.Clear method.
Executing the example requires that the repository contains a modeling container with the MODEL_SPACE identifier. The modeling container must include a metamodel with the METAMODEL identifier calculated by the problem with the PROBLEM identifier. The metamodel calculation chain must include a model of determinate equation with the MODEL identifier.
Add links to the Dal, Metabase, Ms, Transform system assemblies.
Sub ModelParams;
Var
mb: IMetabase;
Ms: IMetabaseObjectDescriptor;
Problem: IMsProblem;
MetaModel: IMsMetaModel;
Model: IMsModel;
MMParams: ITsModelParams;
TsParam: ITsModelParam;
CalcSett: IMsProblemCalculationSettings;
Calc: IMsProblemCalculation;
Method: IMsDeterministicTransform;
ParamsVals: ITsModelParamValues;
Begin
mb := MetabaseClass.Active;
// Get modeling container
Ms := mb.ItemById("MODEL_SPACE");
// Get metamodel
MetaModel := mb.ItemByIdNamespace("METAMODEL", Ms.Key).Edit As IMsMetaModel;
// Set metamodel parameters
MMParams := MetaModel.Params As ITsModelParams;
MMParams.Clear;
// Add the parameter that determines lower limit of values
TsParam := MMParams.Add;
TsParam.Name := "MIN_VALUE";
TsParam.Id := "MIN_VALUE";
TsParam.Tag := "No default value ";
TsParam.Hidden := True;
TsParam.DataType := DbDataType.Integer;
TsParam.ParamType := TsParamType.Simple;
// Add the parameter that determines upper limit of values
TsParam := MMParams.Add As ITsModelParam;
TsParam.Name := "MAX_VALUE";
TsParam.Id := "MAX_VALUE";
TsParam.Tag := "No default value ";
TsParam.Hidden := True;
TsParam.DataType := DbDataType.Integer;
TsParam.ParamType := TsParamType.Simple;
// Save changes made in the metamodel
(MetaModel As IMetabaseObject).Save;
// Get the model
Model := mb.ItemByIdNamespace("MODEL", Ms.Key).Edit As IMsModel;
Method := Model.Transform.FormulaItem(0).Method As IMsDeterministicTransform;
// Set expression for model calculation based on parameter values
Method.Expression.AsString := "Randbetween({MIN_VALUE}, {MAX_VALUE})";
// Save changes made in the model
(Model As IMetabaseObject).Save;
// Get modeling problem
Problem := mb.ItemByIdNamespace("PROBLEM", Ms.Key).Edit As IMsProblem;
// Set parameters of model calculation
CalcSett := Problem.CreateCalculationSettings;
// Set parameter values
ParamsVals := CalcSett.ParamValues As ITsModelParamValues;
ParamsVals.FindById("MIN_VALUE").Value := -100;
ParamsVals.FindById("MAX_VALUE").Value := 100;
CalcSett.FactIncluded := True;
// Calculate
Calc := Problem.Calculate(CalcSett);
Calc.Run;
End Sub ModelParams;
After executing the example two parameters are created in the METAMODEL metamodel. A formula for calculation of the MODEL model is set using these parameters. Then metamodel chain is calculated. Before calculation parameter values are set.
See also: