Accessing the design model with a product applied
To access the design model with a product applied, use the PlModelAccessMode
property of the IContextOption
object.
public void SetSpecifiedProductAccess(ICommandContext c, ICommandParams p)
{
var project = c.App.Workspace.CurrentProject;
var configurationModel = c.App.Workspace.CurrentProject.ProductLineModel.ConfigurationModel;
IProduct product = configurationModel.GetProduct("ACC-0011");
var children = project.GetAllChildren();
c.App.Output.WriteLine("sample", $"Number of models before product application: {children.Count()}");
//Set to enable retrieval and search of only valid design models for the specified product.
c.ContextOption.PlModelAccessMode = PlModelAccessMode.SpecifiedProduct;
c.ContextOption.SpecifiedProduct = product;
children = project.GetAllChildren();
c.App.Output.WriteLine("sample", $"Number of models after product application: {children.Count()}");
//Get the names of valid design models for the specified product
foreach (IModel child in children)
{
c.App.Output.WriteLine("sample", $"Model: {child.Name}");
}
}