Set product application conditions for a model
Use the SetProductApplyCondition
method of the IModel
object to set the product application condition formula. If an unassigned feature name is specified for this model in the product application condition formula, the feature will be automatically assigned. Also, if a feature name already assigned to this model is not used in the condition formula, the assignment with the feature will be automatically released. If an empty string is specified in the condition formula, all feature assignments will be released.
The product application condition formula is a logical formula that treats the "feature name variable" as a boolean variable. If a feature is selected in the configuration, the corresponding "feature name variable" is evaluated as true. The "feature name variable" is written in a format that encloses the feature name or feature unique name in "[" and "]". In addition, the following logical operators and "(",")" to specify the calculation order can be used in the product application condition formula.
Logical expressions:
AND
: logical productOR
: logical sumNOT
: negation
Example: The following product application condition expression is evaluated as true if the feature name "Following driving" or "Front camera" is selected in the configuration.
[Following driving] OR [Front camera]
The following product application condition expression is evaluated as true if the feature name "Constant speed driving" is not selected and "Millimeter wave radar" is selected in the configuration.
NOT [Constant speed driving] AND [Millimeter wave radar]
public void SetProductApplyCondition(ICommandContext c, ICommandParams p)
{
IModel model = c.App.Workspace.CurrentModel;
//Set the condition formula for the model
model.SetProductApplyCondition("[Following driving] OR [Front camera]");
}
The following is an example of copying the product application condition formula of the first selected model to other selected models.
public void CopyProductApplyCondition(ICommandContext c, ICommandParams p)
{
IModelCollection selectedModels = c.App.Window.EditorPage.CurrentEditorView?.SelectedModels;
if ((selectedModels == null) || (selectedModels.Count < 1)) {
c.App.Window.UI.ShowMessageBox("Please select a model in the model editor before executing.");
return;
}
IModel firstModel = selectedModels.First();
var condition = firstModel.GetProductApplyCondition();
foreach (IModel model in selectedModels)
{
if (model.Id != firstModel.Id)
{
model.SetProductApplyCondition(condition);
}
c.App.Output.WriteLine("sample", $"Selected model: {model.Name}");
c.App.Output.WriteLine("sample", $" Product application condition expression: {model.GetProductApplyCondition()}");
}
}