Set relationships between features
This explains how to manipulate relationships between features.
Add constraint relationships between features
To add a constraint relationship between features, use the AddFeatureConstraint method of the IFeatureModel object.
The following values can be specified for the constraint type.
- "Conflicts" ... Exclusive relationship
- "Implicit" ... Mutual dependency
- "Requires" ... Dependency
public void AddFeatureConstraint(ICommandContext c, ICommandParams p)
{
    IFeatureModel featureModel = c.App.Workspace.CurrentProject.ProductLineModel.FeatureModels.FirstOrDefault();
    IFeature sourceFeature = featureModel.GetFeature("Display set distance");
    IFeature targetFeature = featureModel.GetFeature("Following driving");
    //Add dependency between specified features
    featureModel.AddFeatureConstraint(sourceFeature, targetFeature, "Requires");
}
Get constraint relationship between features
To get constraint relationship between features, use the GetFeatureConstraint method of the IFeatureModel object.
public void GetFeatureConstraint(ICommandContext c, ICommandParams p)
{
    IFeatureModel featureModel = c.App.Workspace.CurrentProject.ProductLineModel.FeatureModels.FirstOrDefault();
    IFeature sourceFeature = featureModel.GetFeature("Display distance between vehicles");
    IFeature targetFeature = featureModel.GetFeature("Following");
    //Get constraint relationship between specified features
    var constraint = featureModel.GetFeatureConstraint(sourceFeature, targetFeature, "Requires");
    if (constraint != null)
    {
        c.App.Output.WriteLine("sample", $"There is a dependency between {sourceFeature.Name} and {targetFeature.Name}");
    }
}
Remove constraints between features
To remove constraints between features, use the RemoveFeatureConstraint method of the IFeatureModel object.
public void RemoveFeatureConstraint(ICommandContext c, ICommandParams p)
{
    IFeatureModel featureModel = c.App.Workspace.CurrentProject.ProductLineModel.FeatureModels.FirstOrDefault();
    IFeature sourceFeature = featureModel.GetFeature("Display distance between vehicles");
    IFeature targetFeature = featureModel.GetFeature("Following");
    //Removes dependencies between specified features.
    featureModel.RemoveFeatureConstraint(sourceFeature, targetFeature, "Requires");
}