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?
Solved! Go to Solution.
/// <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} }
/// <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} }