MacroFeature & PMPSelectionbox

Hello,

I am starting a macro feature project but I have some problems with it:

I have a PMPSelectionbox which accept multiple sketches in input.

If the user click on OK button, OnClose method call SaveFeatureData:

void IPropertyManagerPage2Handler9.OnClose(int reason)

{

    if (reason == (int)swPropertyManagerPageCloseReasons_e.swPropertyManagerPageClose_Okay)

        SaveFeatureData();

}

In this method, I am trying to save selections into the feature definition object:

private void SaveFeatureData()
{
    var selMgr = (SelectionMgr)ModelDoc.SelectionManager;

   
    var features = new List();
    var selMarks = new List();
    var drViews = new List();

   
    var count = selMgr.GetSelectedObjectCount2(SelectionMark);
    if (count > 0)
    {
        for (var i = 1; i <= count; i += 1)
        {
            var type = selMgr.GetSelectedObjectType3(i, SelectionMark);
            if (type == SelectionType)
            {
                var selection = selMgr.GetSelectedObject6(i, SelectionMark);
                if (selection is Feature)
                {
                    features.Add((Feature)selection);
                    selMarks.Add(SelectionMark);
                    drViews.Add(null);
                }
            }
        }
    }

   

    if (Feature == null)
    {
        Feature = ModelDoc.FeatureManager.InsertMacroFeature3
        (
            BaseName: "MacroFeature",
            ProgId: "Namespace.MacroFeature",
            MacroMethods: null,
            ParamNames: null,
            ParamTypes: null,
            ParamValues: null,
            DimTypes: null,
            DimValues: null,
            EditBodies: null,
            IconFiles: null,
            Options: 0
        );
    }

   

    if (Feature != null)
    {
        var data = (MacroFeatureData)Feature.GetDefinition();
        if (data != null)
        {
            var access = data.AccessSelections(ModelDoc, null);
            if (access == true)
            {
                data.SetSelections2
                (
                    Objects: features.ToArray(),
                    SelMarks: selMarks.ToArray(),
                    DrViews: drViews.ToArray()
                );
                Feature.ModifyDefinition(data, ModelDoc, null);
            }
        }
    }
}

At creation time, everything is ok but at edition time, if I add or remove a sketch

from the selection box and I click on OK, the new selection is not saved.

Note: If I run step by step, everything look ok:

- features list is ok

- selmarks list is ok

- Feature.ModifyDefinition returns true

I do not really understand AccessSelections / ReleaseSelection / ModifyDefinition mechanism

Some help will be welcome.

SolidworksApi macros