Select to view content in your preferred language

If Not Data View Then???

598
4
Jump to solution
06-27-2012 04:14 AM
DaveCouture
Occasional Contributor
I???ve build a few ArcMap Add-ins and they work fine, when running in the Data View mode.  But, if I???m in the Layout View and I start the Add-Ins, ArcMap crashes. Is there a way to get a message, instead of a crash, when the user is not in Data View?  Or, is there a way to have an Add-In to work in both Data View and Layout view?
0 Kudos
1 Solution

Accepted Solutions
NeilClemmons
Honored Contributor
The document's active view will be either a map or a page layout so all you should need to do is check the type.

If TypeOf My.ArcMap.Document.ActiveView Is IMap Then   ' document is in Data view ElseIf TypeOf My.ArcMap.Document.ActiveView Is IPageLayout Then   ' document is in Layout view End If


I don't work with addins, but for a standard ICommand implementation it would look like the code below.  There should be something similar for an addin.

Public ReadOnly Property Enabled() As Boolean Implements ESRI.ArcGIS.SystemUI.ICommand.Enabled         Get             Dim mxDocument As IMxDocument = DirectCast(m_application.Document, IMxDocument)              ' Enabled as long as the document is in Data view.             Return (TypeOf mxDocument.ActiveView Is IMap)         End Get     End Property

View solution in original post

0 Kudos
4 Replies
NeilClemmons
Honored Contributor
It depends on what your addins do.  First of all, make sure you're getting your references correctly.  For instance, if you want to do something like add elements to the graphics container then don't get the graphics container reference from something like IMxDocument.ActiveView.  The ActiveView property returns a map while in Data view and a page layout while in Layout view.  Also, you can simply disable your addin while in the incorrect view.  If it only works in Data view then check IMxDocument.ActiveView to see if it is a page layout and disable your addin if it is.
0 Kudos
DaveCouture
Occasional Contributor
Thanks Neil, that make sense.  I like the option to have the tool disabled (button grey out), when in Layout VIew. I'm just unsure how to build the condition to check if the Layout View is on, tho.  I've been reading on the IActiveView and IMxDocument, but I can't find solutions on how to determine which view is activated.

This is what I use in my code, to set the Active View:

Dim pMap As IMap = My.ArcMap.Document.ActiveView
0 Kudos
NeilClemmons
Honored Contributor
The document's active view will be either a map or a page layout so all you should need to do is check the type.

If TypeOf My.ArcMap.Document.ActiveView Is IMap Then   ' document is in Data view ElseIf TypeOf My.ArcMap.Document.ActiveView Is IPageLayout Then   ' document is in Layout view End If


I don't work with addins, but for a standard ICommand implementation it would look like the code below.  There should be something similar for an addin.

Public ReadOnly Property Enabled() As Boolean Implements ESRI.ArcGIS.SystemUI.ICommand.Enabled         Get             Dim mxDocument As IMxDocument = DirectCast(m_application.Document, IMxDocument)              ' Enabled as long as the document is in Data view.             Return (TypeOf mxDocument.ActiveView Is IMap)         End Get     End Property
0 Kudos
DaveCouture
Occasional Contributor
Thanks a bunch, Neil!
0 Kudos