I have a windows forms application (Z application), is it possible to start Arcmap, and start the Editor or any other command I desire from the application (Z appliction) ?

So far I was able to initialize and bind the license, so now I am able to access feature classes using Arcobjects without starting arcmap, but I want to start Arcmap, add featurelayers, start editing, and then save those edits. The only missing part is the part where I am able to run arcmap and access the application to get the document.

here is the flow

        IAoInitialize s = new AoInitializeClass();

next step would be to start arcmap


Arcmap starts, then this is where I am stuck, I want to access the arcmap application, so I can get mxdocument, and commands.


1 Answer 1


This is VB.net rather than C# but you can probably get the process First import the libraries you need :e.g.

Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.ArcMapUI
Imports ESRI.ArcGIS.Carto


Then create an application :

Private m_App As ESRI.ArcGIS.Framework.IApplication

Instantiate and create a document with some data sources :

Public Sub StartArcMap()
        If m_pDoc Is Nothing Then
            System.Windows.Forms.Cursor.Current = Cursors.WaitCursor

        'Start arcmap
        'm_pDoc = New MxDocumentClass

        Dim FrameDoc As ESRI.ArcGIS.Framework.IDocument = New 
        m_App = FrameDoc.Parent
        m_App.Visible = True

        Dim pDoc As IDocument = m_App.Document()
        Dim pMxDoc As IMxDocument = CType(pDoc, IMxDocument)

        'Show arcmap
        m_App.Visible = True

        'Disable and enable buttons
        cmdStartArcMap.Enabled = False
        cmdAddData.Enabled = True
        cmdQuitArcMap.Enabled = True
        System.Windows.Forms.Cursor.Current = Cursors.Default

        Dim pActiveView As IActiveView
        pActiveView = pMxDoc.ActiveView

        Dim pFLayer As IFeatureLayer
        pFLayer = New FeatureLayer
        'Dim pFClass As IFeatureClass

        Dim pShpWSF As GxShapefileFactory
        pShpWSF = New GxShapefileFactory

        Dim DataPath As String
        DataPath = **"C:\DATA STUFF"**
        'DataPath = **"SOME WHERE"**
        'AddShapeFile(DataPath, m_pApp, pMxDoc, pActiveView)
        AddData(m_App, DataPath)

    End If
End Sub

Finally create the MXd and add the data :

Public Sub AddData(ByRef m_Application, Datapath)
        Dim objFactory As IObjectFactory = TryCast(m_Application, 

    'Use reflection to get ClsID of ShapefileWorkspaceFactory.
    Dim shpWkspFactType As Type = GetType(ShapefileWorkspaceFactoryClass)
    Dim typeClsID As String = shpWkspFactType.GUID.ToString("B")

    Dim workspaceFactory As IWorkspaceFactory = 
    DirectCast(objFactory.Create(typeClsID), IWorkspaceFactory)
    Dim featureWorkspace As IFeatureWorkspace =  
    DirectCast(workspaceFactory.OpenFromFile(Datapath, 0), 

    Dim MxDType As Type = GetType(IMxDocument)
    Dim MxDClsID As String = MxDType.GUID.ToString("B")

    'Dim pMxDoc As IMxDocument = DirectCast(objFactory.Create(MxDClsID), 
    Dim pMxDoc As IMxDocument = CType(m_App.Document, IMxDocument)

    Dim featureLayer As IFeatureLayer = 
    DirectCast(objFactory.Create("esriCarto.FeatureLayer"), IFeatureLayer)
    featureLayer.FeatureClass = featureWorkspace.OpenFeatureClass("wPoints")
    featureLayer.Name = featureLayer.FeatureClass.AliasName

    'Add the layer to the document.
    Dim document As IBasicDocument = DirectCast(m_Application.Document, 

    Dim pFClass As IFeatureClass
    pFClass = featureWorkspace.OpenFeatureClass("wPoints")
    'pFClass = featureLayer.FeatureClass

    Dim pFeature As IFeature = pFClass.GetFeature(20)

That should be enough to see how one gets a handle on the Application, the Mxd, data and objects there in?

  • Thank you, but doesn't creating an MxDocumentClass object automatically start arcmap and creates a document ? if so, how can I make it where I use the arcmap that is already started by the process ? I am trying to run arcmap in the background as I do the editing.
    – ZZZ
    Commented Mar 23, 2017 at 13:01
  • You need to get the window handle of the process from the OS and use that to create the application. Its a long time since I did that, I have the code somewhere but it might take afew days before I could track it down. I should warn you however that I tried something similar the otherway around (opening MS Access repeatedly from ArcGIS) I never did figure out a way to Kill it properly afterward.
    – AnserGIS
    Commented Mar 23, 2017 at 14:17
  • I'll keep that in mind, thank you for your help. I'll just start Arcmap from the document and hide it instead of using Process.Start, if you get to track the code you have please share :).
    – ZZZ
    Commented Mar 23, 2017 at 14:34
  • 1
    m_app.Visible = False; resources.arcgis.com/en/help/arcobjects-net/componenthelp/… will start ArcMap and allow you to do all your usual tasks but does not show the application (except in task manager).. when you're done setting up then set the m_app.Visible to True and the ArcMap session will appear. A MxDocument does not need to be persisted to a file, if you want to keep the document you will need to save m_app.SaveDocument(pSavePath); resources.arcgis.com/en/help/arcobjects-net/componenthelp/… Commented Mar 23, 2017 at 23:30

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.