Assigning features to a model
Feature assignment to a model can be done using the methods of the IModel
object.
Assigning features
To assign a feature, use the AssignFeature
method of the IModel
object. To assign a feature by specifying its name, use the AssignFeatureByName
method.
public void AssignFeature(ICommandContext c, ICommandParams p)
{
IModel model = c.App.Workspace.CurrentModel;
//Assign a feature with the specified name to the model
model.AssignFeatureByName("camera");
//Assign all features with the specified name to the model
model.AssignFeaturesByName("camera, radar, airbag");
//Assign by feature
IFeature feature = ...
model.AssignFeature(feature);
}
Get assigned features
To get the features assigned to a model, use the GetAssignedFeatures
method of the IModel
object.
public void GetAssignedFeatures(ICommandContext c, ICommandParams p)
{
IModel model = c.App.Workspace.CurrentModel;
IFeatureCollection features = model.GetAssignedFeatures();
foreach ( IFeature feature in features )
{
c.App.Output.WriteLine("sample", $"Feature Name: {feature.Name}, Kind: {feature.VariationKind}");
}
}
Release feature assignments
To release all features assigned to a model, use the ReleaseAllAssignedFeatures
method of the IModel
object. If you want to release some feature assignments, you can release them by specifying the feature name with the ReleaseAssignedFeatureByName
method.
public void ReleaseAssignedFeatures(ICommandContext c, ICommandParams p)
{
IModel model = c.App.Workspace.CurrentModel;
//Release all assigned features from the model
model.ReleaseAllAssignedFeatures();
//Release the assigned feature with the specified name from the model
model.ReleaseAssignedFeatureByName("Camera");
}