Select to view content in your preferred language

How to save edits after operation

1087
3
Jump to solution
02-28-2012 08:57 AM
AlexanderGray
Honored Contributor
I have a requirement to save the edit session after a set number of edit operations.  I do the save in the ieditevents2.onstopoperation.  It works fine for lines in a file geodatabase but for points in the same geodatabase, it crashes arcmap.  It works ok for change or delete point but for create point, it crashes arcmap.  No exception, the save is ok, arcmap just crashes after all the code is executed correctly.
I created a little sample arcmap extension that saves after every edit:


Private m_application As IApplication   Private m_editor As IEditor   Private m_editEvents As IEditEvents2_Event     Public Sub Shutdown() Implements ESRI.ArcGIS.esriSystem.IExtension.Shutdown     RemoveHandler m_editEvents.OnStopOperation, AddressOf saveedits     m_application = Nothing   End Sub    Public Sub Startup(ByRef initializationData As Object) Implements ESRI.ArcGIS.esriSystem.IExtension.Startup     m_application = CType(initializationData, IApplication)     If m_application Is Nothing Then Return     m_editor = GetEditorFromArcMap(m_application)     m_editEvents = DirectCast(m_editor, IEditEvents2_Event)     AddHandler m_editEvents.OnStopOperation, AddressOf saveedits   End Sub     Private Sub saveedits()     Try       Dim wk As IWorkspace = m_editor.EditWorkspace       m_editor.StopEditing(True)       m_editor.StartEditing(wk)     Catch ex As Exception       Trace.WriteLine(ex)     End Try    End Sub  Any thoughts? 
0 Kudos
1 Solution

Accepted Solutions
GregRieck
Frequent Contributor
Hi Alexander,

Have you considered just saving the edits? I call the save edits command without issue a lot after specific edit events and have never had an issue with a crash.

        /// <summary>         /// Find a command and click it programmatically.         /// </summary>         /// <param name="commandName">A System.String that is the name of the command to return. Example: "esriFramework.HelpContentsCommand" or "{D74B2F25-AC90-11D2-87F8-0000F8751720}"</param>         /// <param name="subtype">The specific item in the command that should be called. Pass -1 for none.</param>         ///<remarks>Refer to the ArcGIS document http://help.arcgis.com/en/sdk/10.0/ArcObjects_NET/conceptualhelp/index.html#/arcmap_commands/00010000029s000000/ for a listing of available CLSID's and ProgID's that can be used as the commandName parameter.</remarks>         public static void FindCommandAndExecute(System.String commandName, int subtype)         {             try             {                 ICommandBars commandBars = afoApp.Document.CommandBars;                 ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();                 uid.Value = commandName; //Example: "esriFramework.HelpContentsCommand" or "{D74B2F25-AC90-11D2-87F8-0000F8751720}"                 if (subtype > -1)                     uid.SubType = subtype;                 ICommandItem commandItem = commandBars.Find(uid, false, false);                 if (commandItem != null)                     commandItem.Execute();             }             catch (Exception ex)             {                 RecordError(ex);             }         }       public static void ForceSave()     {       FindCommandAndExecute("esriEditor.SaveEditsCommand", -1);//{59D2AFD2-9EA2-11D1-9165-0080C718DF97}     } 


Greg

View solution in original post

0 Kudos
3 Replies
GregRieck
Frequent Contributor
Hi Alexander,

Have you considered just saving the edits? I call the save edits command without issue a lot after specific edit events and have never had an issue with a crash.

        /// <summary>         /// Find a command and click it programmatically.         /// </summary>         /// <param name="commandName">A System.String that is the name of the command to return. Example: "esriFramework.HelpContentsCommand" or "{D74B2F25-AC90-11D2-87F8-0000F8751720}"</param>         /// <param name="subtype">The specific item in the command that should be called. Pass -1 for none.</param>         ///<remarks>Refer to the ArcGIS document http://help.arcgis.com/en/sdk/10.0/ArcObjects_NET/conceptualhelp/index.html#/arcmap_commands/00010000029s000000/ for a listing of available CLSID's and ProgID's that can be used as the commandName parameter.</remarks>         public static void FindCommandAndExecute(System.String commandName, int subtype)         {             try             {                 ICommandBars commandBars = afoApp.Document.CommandBars;                 ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();                 uid.Value = commandName; //Example: "esriFramework.HelpContentsCommand" or "{D74B2F25-AC90-11D2-87F8-0000F8751720}"                 if (subtype > -1)                     uid.SubType = subtype;                 ICommandItem commandItem = commandBars.Find(uid, false, false);                 if (commandItem != null)                     commandItem.Execute();             }             catch (Exception ex)             {                 RecordError(ex);             }         }       public static void ForceSave()     {       FindCommandAndExecute("esriEditor.SaveEditsCommand", -1);//{59D2AFD2-9EA2-11D1-9165-0080C718DF97}     } 


Greg
0 Kudos
AlexanderGray
Honored Contributor
Thanks, I gave than a run and it works.  I was hoping to make the code independent of commands but I guess if it is dependent on ArcMap editor extension it doesn't really matter any way.
0 Kudos
AlexanderGray
Honored Contributor
seems like my fears of running IWorkspaceFactory.Copy during an edit session (after ICommandItem.execute where the command is saveedits) were unfounded.  Calling the save edits command will work.
0 Kudos