Accessing application and document objects


Summary
One of the first tasks when customizing an ArcGIS for Desktop application is to access the application or document object. Together, these objects act as the central point of entry to other objects in the ArcGIS system. This topic shows common ways of getting a reference to the application object in your .NET custom components.


About accessing application and document objects

The application framework provides ways to customize and extend the user interface (UI) for ArcGIS for Desktop applications. You can access the application object with the methods in the following table:
Implementation
Reference
Method and parameter
Command, Tool, and ToolControl
IApplication
ICommand.OnCreate() hook parameter
MultiItem command
IApplication
IMultiItem.OnPopup() hook parameter
Extension
IApplication
IExtension.Startup() initializationData parameter
Dockable window
IApplication
With certain customizations, you get a document object directly. In these cases, you can access the application object by casting the document object to IDocument and accessing the parent property. See the following table:
Implementation
Reference
Method and parameter
Contents View (ArcMap)
IMxDocument
IContentsView.Activate() document parameter
Contents View (ArcScene)
ISxDocument
ISxContentsView.Activate() document parameter
Contents View (ArcGlobe)
IDocument
IContentsView2.BasicActivate() document parameter
See the following code example:
[C#]
//ArcMap.
IMxDocument mapDocument = parameter;
IDocument document = mapDocument as IDocument;
IApplication application = document.Parent;
[VB.NET]
'ArcMap.
Dim mapDocument As IMxDocument = parameter
Dim document As IDocument = CType(mapDocument, IDocument)
Dim application As IApplication = document.Parent

Getting a reference to the application object

You can also get a reference to the application object indirectly from other custom component implementations. For example, if you write an Editor extension, IExtension.Startup gives you a reference to the Editor object, then you can use the IEditor.Parent property to get to the IApplication object.
As a last resort, if you can't get a reference to the application object in your code, you can instantiate a new AppRef object. Once you get the application object, you can access the current document and templates, status bar, selected tool, and application extensions.
To programmatically find an application extension, use the IApplication.FindExtensionByCLSID method. This method takes the unique identifier (UID) of the extension as the input parameter. A list of the Esri extension UIDs is provided in the Help system.






Development licensing Deployment licensing
ArcGIS for Desktop Basic ArcGIS for Desktop Basic
ArcGIS for Desktop Standard ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced ArcGIS for Desktop Advanced