Automate ArcGIS Desktop applications


PurposeThis sample shows how to automate ArcGIS Desktop applications (ArcMap, ArcScene, and ArcGlobe) from stand-alone .NET applications. To programmatically start a new application session, you can use the new operator to create a new Document object (MxDocument, SxDocument, or GMxDocument). Once you successfully create the new Document object, a new application session is started.

The stand-alone application also allows you to add layers to that new session of the application. The IObjectFactory is used to create the new layers inside the application's process space. In addition, it shows how to programmatically clean up and shut down the application properly, including how to handle the case when the application has been closed by the user manually (with AppROT event).

Development licensing Deployment licensing
ArcView ArcView
ArcEditor ArcEditor
ArcInfo ArcInfo

How to use

See Using the samples for help on compiling, setting up the debugger, and running the sample (either an exe or dll).

  1. Open and compile the sample project in Visual Studio 2005.
  2. Run DesktopAutomationCS.exe or DesktopAutomationVB.exe depending on the language version.
  3. Select ArcMap, ArcScene, or ArcGlobe from the application drop-down list and click Start to start a new application session. Note the change in the state of the Start (becomes unavailable) and the Exit (becomes available) buttons.
  4. Type the path of a valid shapefile in the text box. Click Add Layer to add it to the new application session.
  5. Click Exit to shut down the application session. Note the change in the state of the Start (becomes available) and the Exit (becomes unavailable) buttons.
  6. Steps 7–9 demonstrate how to handle modal dialog boxes when exiting the application.
  7. Start the application as in Step 3.
  8. Open a modal dialog box of the application; for example, click the Add Data button.
  9. With the Add Data dialog box displayed, click Exit to shut down the application session.
  10. Steps 11–12 show how to handle the manual application shutdown in an automation session.
  11. Start the application as in Step 3.
  12. Close the newly started application manually by choosing File, then Exit or click the Close (X) button on the title bar. Note the change in the state of the Start (becomes available) and the Exit (becomes unavailable) buttons.

Form1.cs Form for automation demonstration showing how to start an ArcGIS Desktop application.
Download the C# files
Form1.vb Form for automation demonstration showing how to start an ArcGIS Desktop application.
Download the VB.NET files

Download the files for all languages

See Also:

How to automate ArcGIS Desktop applications