3

I have made an attempt to create an ArcObjects addin to help with some workflows here in the office. I apologize in advance if I have something fundamentally wrong with the code. This is my first ArcObjects endeavor. Essentially I have geodatabases with a large number of feature classes. Each feature class has the fields "DateModified" and "ModifiedBy" and I am hoping to populate them as edits are made. I am aware of editor tracking currently in ArcGIS, but the powers that be would like to track edits without changing current data models.

It appears that the code below crashes ArcMap when it attempts to store the feature.

So my questions are 1) Can someone tell me why my code causes ArcMap to crash? 2) Are there easier ways to accomplish what I have been tasked with? Thanks in advance.

I have the following code:

Public Class TrackEditsExtension
 Inherits ESRI.ArcGIS.Desktop.AddIns.Extension
 Public Sub New()
 End Sub
 'Invoked when the Editor Extension is loaded
 Protected Overrides Sub OnStartup()
 AddHandler Events.OnStartEditing, AddressOf Events_OnStartEditing
 AddHandler Events.OnStopEditing, AddressOf Events_OnStopEditing
 End Sub
 'Invoked at the start of the Editor Session
 Private Sub Events_OnStartEditing()
 AddHandler Events.OnCreateFeature, AddressOf Events_OnCreateChangeFeature
 AddHandler Events.OnChangeFeature, AddressOf Events_OnCreateChangeFeature
 System.Windows.Forms.MessageBox.Show("Editor tracking extension enabled.")
 End Sub
 'Invoked at the end of the Edit session
 Private Sub Events_OnStopEditing()
 RemoveHandler Events.OnCreateFeature, AddressOf Events_OnCreateChangeFeature
 RemoveHandler Events.OnChangeFeature, AddressOf Events_OnCreateChangeFeature
 End Sub
 'Invoked when a feature is created or modified
 Private Sub Events_OnCreateChangeFeature(ByVal obj As ESRI.ArcGIS.Geodatabase.IObject)
 Dim feature As IFeature = CType(obj, IFeature)
 Dim dateIndex As Integer = feature.Fields.FindField("DateModified")
 Dim nameIndex As Integer = feature.Fields.FindField("ModifiedBy")
 Dim changeMade As Boolean = False
 If dateIndex > 0 Then
 feature.Value(dateIndex) = DateTime.Now
 changeMade = True
 End If
 If nameIndex > 0 Then
 feature.Value(nameIndex) = Environ("USERNAME")
 changeMade = True
 End If
 If changeMade = True Then
 feature.Store()
 End If
 End Sub
 Protected Overrides Sub OnShutdown()
 End Sub
End Class
asked Jun 26, 2014 at 19:48
2
  • 1
    Comment out the Store call. help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/… Store should not be called inside of edit events, such as OnCreateFeature, OnChangeFeature or OnDeleteFeature. Even if you are modifying the geometry or other field values, Store will be called once the event is complete. Commented Jun 26, 2014 at 19:55
  • Great, thank you! I will to give you rep if you post your comment as an answer. Commented Jun 26, 2014 at 20:19

1 Answer 1

4

If you comment out the Store call, you should be good: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//0025000007wv000000

Store should not be called inside of edit events, such as OnCreateFeature, OnChangeFeature or OnDeleteFeature. Even if you are modifying the geometry or other field values, Store will be called once the event is complete.

answered Jun 26, 2014 at 20:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.