Ok I think I get it now but information is really scattered and unless you know what you are looking for its hit and miss. So in VB6 I used to use the ICommand_Enabled event in each command for enabling/disabling the button. from what I have read, you now have to over-ride the Enabled() event of the button. So really I keep local variables for my basic elements, then assign them at OnCreate, and toggle the button at Enabled(). For each command button something like: Private m_application As IApplication
Private m_mxdocument As IMxDocument
Private m_map As IMap
Private m_pExt As IExtensionConfig
Public Overrides Sub OnCreate(ByVal hook As Object)
If Not hook Is Nothing Then
m_application = CType(hook, IApplication)
m_mxdocument = CType(m_application.Document, IMxDocument)
m_map = m_mxdocument.ActivatedView.FocusMap
m_pExt = CType(m_application.FindExtensionByName("myExt.extMain"), IExtensionConfig)
'blah
End If
End Sub
Public Overrides ReadOnly Property Enabled() As Boolean
Get
m_mxdocument = CType(m_application.Document, IMxDocument)
m_map = m_mxdocument.ActivatedView.FocusMap
If (m_pExt IsNot Nothing) Then
If (m_pExt.State = esriExtensionState.esriESEnabled And m_map.LayerCount > 0) Then
Enabled = True
Else
Enabled = False
End If
Else
Enabled = False
End If
End Get
End Property
Does that look about right? Couple things..In the samples I have looked at they use ActivatedView instead of ActiveView. I've read the documentation and still dont get how you use each one or how they are different. Also, notice above that in the Enabled routine I am getting a reference to the document and map again, even though I have already got them at the OnCreate event. Well it turns out an issue I had in my VB6 project also happens here. There are two ways to open a map 1)by double-clicking on the MXD in Windows Explorer and 2)by selecting the map through the ArcMap Dialog box that pops up when you open up ArcMap on its own. Well when you do #2 the variables that hold the document and map get lost. You have to re-get them on the Enabled event. Why does this happen? Is it a bug? ESRI Tech support knows about it as I reported it some time ago. If it is a bug it has not been resolved as of 10.0. I haven't tested with 10.1 as I haven't moved to that yet.So there it is. Please feel free to comment as to my progress. Its slow but in the end it will take me through another 10 years I hope with this extension.AGP