private IExtensionConfig m_MyExtension; public override void OnCreate(object hook) { if (hook == null) return; m_application = hook as IApplication; if (m_application != null) { m_MyExtension = m_application.FindExtensionByName("My Extension") as IExtensionConfig; } } public override bool Enabled { get { bool enabled = false; try { if (m_MyExtension != null && m_MyExtension.State == esriExtensionState.esriESEnabled) enabled = AMethodThatMightThrowAnException(); } catch (Exception ex) { MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace); m_MyExtension = null; } return enabled; } }
As you state, OnCreate is only fired when the command is created, whereas Enabled is fired continuously (which is also why you shouldn't have any extensive code in that subroutine). This will react to any changes in the environment, like enabling the extension.
Public Overrides ReadOnly Property Enabled() As Boolean Get Dim ext As ESRI.ArcGIS.esriSystem.IExtension = m_application.FindExtensionByName("myExtension.Extension") Dim extConf As ESRI.ArcGIS.esriSystem.IExtensionConfig = ext If extConf.State = ESRI.ArcGIS.esriSystem.esriExtensionState.esriESEnabled Then Return True Else Return False End If End Get End Property
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.