Edit definition allows to modify the parameters of an existing feature. Edit definition is called when Edit Feature command is clicked form the feature manager tree.

Edit Feature Command
Edit Feature Command

The typical workflow which should be followed when feature is edited

  • Get the definition of the feature via IFeature::GetDefinition
  • Rollback the feature in the tree via IMacroFeatureData::AccessSelections. This will ensure that all the feature selections and edit bodies are available.
  • Get the parameters of current macro feature via GetParameters
  • Create user interface and allow user to edit parameters. The recommended way to use Property Manager Pages to have a native look and feel of your feature. Use SwEx.PMPage framework for simplified way of creating property manager pages.
  • Once user interface is closed
protected override bool OnEditDefinition(ISldWorks app, IModelDoc2 model, IFeature feature)
{
    var featData = feature.GetDefinition() as IMacroFeatureData;

    //rollback feature
    featData.AccessSelections(model, null);

    //read current parameters
    var parameters = GetParameters(feature, featData, model);

    //Show property page or any other user interface
    var res = ShowPage(parameters);

    if (res)
    {
        //set parameters and update feature data
        SetParameters(model, feature, featData, parameters);
        feature.ModifyDefinition(featData, part, null);
    }
    else
    {
        //cancel modifications
        featData.ReleaseSelectionAccess();
    }

    return true;
}

It is important to use the same pointer to IMacroFeatureData while calling the IMacroFeatureData::AccessSelections, GetParameters, SetParameters, IFeature::ModifyDefinition and IMacroFeatureData::ReleaseSelectionAccess methods.