Automate ArcGIS Desktop applications


Purpose
This 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 the new session of the application. 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).

How to use

See How to use ArcGIS samples for help on compiling, setting up the debugger, and running the sample. If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

Automating an ArcGIS Desktop application
  1. Open the solution file in Visual Studio and compile the sample.
  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. Notice 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, and click Add Layer to add it to the new application session.
  5. Click Exit to shut down the application session. Notice the change in the state of the Start (becomes available) and the Exit (becomes unavailable) buttons.

Handling modal dialog boxes when exiting the application
  1. Start a new application session.
  2. Open a modal dialog box of the application; for example, click the Add Data button.
  3. With the Add Data dialog box displayed, click Exit to shut down the application session.

Handling the manual application shutdown in an automation session
  1. Start a new application session.
  2. Close the application manually by clicking File, then clicking Exit or click the Close (X) button on the title bar. Notice 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:

Automating the ArcGIS Desktop applications




Development licensing Deployment licensing
ArcView ArcView
ArcEditor ArcEditor
ArcInfo ArcInfo