AnsweredAssumed Answered

Execute SaveEditsCommand in OnCreateFeature edit event creates another feature

Question asked by harlan.marshall on Jan 2, 2018
Latest reply on Jan 3, 2018 by harlan.marshall

Working with ArcGIS Desktop 10.5.1 and .NET SDK. Building ArcMap add-in extension. I'm trying to cause a newly created feature to be saved programatically as the last operation of the OnCreateFeature edit event. The problem I'm having is that when the save edit command completes, another feature is created and the OnCreateFeature event is fired again. I do not understand what is causing another feature to be created. Here's the important parts of my OnCreateFeature event handler:

private void m_editEvents_OnCreateFeature(ESRI.ArcGIS.Geodatabase.IObject obj)
{
IFeature pFeature = obj as IFeature;

// Set feature case number and other stuff...

// Save the newly created feature so that the feature and case number is commited
UID pUID = new UID();
pUID.Value = "{59D2AFD2-9EA2-11D1-9165-0080C718DF97}"; // esriEditor.SaveEditsCommand
ICommandItem pCmdItem = ArcMap.Application.Document.CommandBars.Find(pUID, false, false);
pCmdItem.Execute();
}

 

I know that the SaveEditsCommand internally executes StopEditing and StartEditing. However, I do not see why another feature is created and goes into endless loop (create, save, create, save, on and on).

 

If there is a better way to accomplish saving automatically on creation, I would appreciate greatly finding out how to do it.

The reason I need this to happen is to commit the feature with its calculated case number to the geodatabase instantly so that other concurrent editors can get the next available sequential number from the feature class itself.

Outcomes