ArcObjects Library Reference

Get Editor from ArcMap Snippet

Returns a reference to the ESRI editor object.

[C#]

///<summary>Returns a reference to the ESRI editor object.</summary>
///  
///<param name="mxApplication">An IMxApplication interface, ie. ArcMap.</param>
///   
///<returns>An IEditor2 interface, the ArcMap Editor.</returns>
///   
///<remarks>You could also use the: application.FindExtensionByName("ESRI Object Editor") to get the extension object.</remarks>
public ESRI.ArcGIS.Editor.IEditor2 GetEditorFromArcMap(ESRI.ArcGIS.ArcMapUI.IMxApplication mxApplication)
{
  if(mxApplication == null)
  {
    return null;
  }
  ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
  uid.Value = "{F8842F20-BB23-11D0-802B-0000F8037368}";
  ESRI.ArcGIS.Framework.IApplication application = mxApplication as ESRI.ArcGIS.Framework.IApplication; // Dynamic Cast
  ESRI.ArcGIS.esriSystem.IExtension extension = application.FindExtensionByCLSID(uid);
  ESRI.ArcGIS.Editor.IEditor2 editor2 = extension as ESRI.ArcGIS.Editor.IEditor2; // Dynamic Cast

  return editor2;
}
[Visual Basic .NET]

'''<summary>Returns a reference to the ESRI editor object.</summary>
'''  
'''<param name="mxApplication">An IMxApplication interface, ie. ArcMap.</param>
'''   
'''<returns>An IEditor2 interface, the ArcMap Editor.</returns>
'''   
'''<remarks>You could also use the: application.FindExtensionByName("ESRI Object Editor") to get the extension object.</remarks>
Public Function GetEditorFromArcMap(ByVal mxApplication As ESRI.ArcGIS.ArcMapUI.IMxApplication) As ESRI.ArcGIS.Editor.IEditor2

  If mxApplication Is Nothing Then
    Return Nothing
  End If

  Dim uid As ESRI.ArcGIS.esriSystem.UID = New ESRI.ArcGIS.esriSystem.UIDClass
  uid.Value = "{F8842F20-BB23-11D0-802B-0000F8037368}"
  Dim application As ESRI.ArcGIS.Framework.IApplication = TryCast(mxApplication, ESRI.ArcGIS.Framework.IApplication) ' Dynamic Cast
  Dim extension As ESRI.ArcGIS.esriSystem.IExtension = application.FindExtensionByCLSID(uid)
  Dim editor2 As ESRI.ArcGIS.Editor.IEditor2 = TryCast(extension, ESRI.ArcGIS.Editor.IEditor2) ' Dynamic Cast

  Return editor2

End Function


Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.ArcMapUI
  • ESRI.ArcGIS.Editor
  • ESRI.ArcGIS.Framework
  • ESRI.ArcGIS.System