AnsweredAssumed Answered

ArcMap add-in: How to add button operation to undo/redo stack

Question asked by corydavis343 on May 16, 2019
Latest reply on May 31, 2019 by sean_jones-esristaff

I've built an add-in with several buttons which initiate an editing session to perform their actions. I would like to push the operation to ArcMap's operation stack so the undo/redo buttons are enabled, but I can't figure out how.

 

Here is a snippet of the action of one button. This one reduces the font size of all selected features. Is it possible to add this operation to the stack after it is used?

IFeatureLayer currLayer = currMap.Layer[j] as IFeatureLayer;
ISelectionSet ss = ((IFeatureSelection)currLayer).SelectionSet;
if(ss.Count > 0 && currLayer.FeatureClass.FindField(attributeName) > -1)
{
    IWorkspaceEdit wse = ((IDataset)currLayer.FeatureClass).Workspace as IWorkspaceEdit;
    wse.StartEditing(true);
    wse.StartEditOperation();

    //Update all annotations in the selection set
    IFeature currFeature;
    int attributeIndex;
    IEnumIDs ids = ss.IDs;
    ids.Reset();
    int id = ids.Next();
    while(id > -1)
    {
        currFeature = currLayer.FeatureClass.GetFeature(id);
        attributeIndex = currFeature.Class.FindField(attributeName);
        currFeature.Value[attributeIndex] = currFeature.Value[attributeIndex] - 0.5;
        currFeature.Store();
        id = ids.Next();
    }
    mxd.ActiveView.Refresh();
    wse.StopEditOperation();
    wse.StopEditing(true);
}

Outcomes