Refer to the document/application in an add-in?

588
2
05-08-2013 09:04 AM
JoeMcCollum
New Contributor
Is it possible to refer to the Application/document in an add-in?

I've successfully attached a dockable window to a button - now what do I do?

It doesn't seem to like:

Dim pMxDoc As IMxDocument = new MxDocument
nor can you do:

Dim pMxDoc As IMxDocument = m_application.Document
or maybe you can but how do you set m_application in a dockable window?

ANSWER: Add the lines in bold

Private m_pApp As ESRI.ArcGIS.Framework.IApplication

Public Sub New(ByVal hook As Object)
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Me.Hook = hook
m_pApp = hook

End Sub
.....
then down in your button_click do:

Dim pMxDocument As IMxDocument = m_pApp.Document

Thanks!
0 Kudos
2 Replies
RichardWatson
Frequent Contributor
var applicationObjectType = Type.GetTypeFromCLSID(typeof(AppRefClass).GUID);
                        var rawApplicationObject = Activator.CreateInstance(applicationObjectType);
                        _application = (IApplication)rawApplicationObject;
0 Kudos
TerryGiles
Occasional Contributor III
Since you're working with an Add-In you can also just reference the internal ArcMap class & it's Document member which returns IMxDocument -

IMxDocument mxdoc = ArcMap.Document;
0 Kudos