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:
<SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">m_editEvents_OnCreateFeature</SPAN><SPAN class="punctuation token">(</SPAN>ESRI<SPAN class="punctuation token">.</SPAN>ArcGIS<SPAN class="punctuation token">.</SPAN>Geodatabase<SPAN class="punctuation token">.</SPAN>IObject obj<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
IFeature pFeature <SPAN class="operator token">=</SPAN> obj <SPAN class="keyword token">as</SPAN> IFeature<SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">// Set feature case number and other stuff...</SPAN>
<SPAN class="comment token">// Save the newly created feature so that the feature and case number is commited</SPAN>
UID pUID <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">UID</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
pUID<SPAN class="punctuation token">.</SPAN>Value <SPAN class="operator token">=</SPAN> <SPAN class="string token">"{59D2AFD2-9EA2-11D1-9165-0080C718DF97}"</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// esriEditor.SaveEditsCommand </SPAN>
ICommandItem pCmdItem <SPAN class="operator token">=</SPAN> ArcMap<SPAN class="punctuation token">.</SPAN>Application<SPAN class="punctuation token">.</SPAN>Document<SPAN class="punctuation token">.</SPAN>CommandBars<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Find</SPAN><SPAN class="punctuation token">(</SPAN>pUID<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
pCmdItem<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Execute</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>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.