public esriExtensionState State { get { return m_enableState; } set { if (m_enableState != 0 && value == m_enableState) return; //Check if ok to enable or disable extension esriExtensionState requestState = value; if (requestState == esriExtensionState.esriESEnabled) { //Cannot enable if it's already in unavailable state if (m_enableState == esriExtensionState.esriESUnavailable) { throw new COMException("Cannot enable extension"); } //Determine if state can be changed esriExtensionState checkState = StateCheck(true); m_enableState = checkState; MessageBox.Show("Enabled"); } else if (requestState == 0 || requestState == esriExtensionState.esriESDisabled) { //Determine if state can be changed esriExtensionState checkState = StateCheck(false); if (checkState != m_enableState) m_enableState = checkState; MessageBox.Show("Disabled"); } } }
namespace RegGSS { [Guid("21fee823-6e9a-43af-a452-f5c8678b6e99")] [ClassInterface(ClassInterfaceType.None)] [ProgId("RegGSS.Extension")] public class Extension : IExtension, IExtensionConfig, IPersistVariant { private IApplication m_application; private IMxDocument m_mxDocument; private esriExtensionState m_enableState; private IApplicationStatus m_appStatus; private IApplicationStatusEvents_Event m_mapStatusEvents; private IActiveViewEvents_Event m_mapEvents; #region IExtension Members /// <summary> /// Name of extension. Do not exceed 31 characters /// </summary> public string Name { get { //TODO: Modify string to uniquely identify extension return "RegGSS Extension"; } } public void Shutdown() { //TODO: Clean up resources m_application = null; //m_docEvents = null; } public void Startup(ref object initializationData) { m_application = initializationData as IApplication; if (m_application == null) return; //TODO: Add code to initialize the extension m_appStatus = m_application as IApplicationStatus; } #endregion #region IExtensionConfig Members public string Description { get { //TODO: Replace description (use for line break) return "RegGSS 9.3" + "Copyright © SFWMD 2010" + "Environmental Resource Regulation" + "Regulatory Support - GIS Section"; } } /// <summary> /// Friendly name shown in the Extension dialog /// </summary> public string ProductName { get { //TODO: Replace return "RegGSS"; } } public esriExtensionState State { get { return m_enableState; } set { if (m_enableState != 0 && value == m_enableState) return; //Check if ok to enable or disable extension esriExtensionState requestState = value; if (requestState == esriExtensionState.esriESEnabled) { //Cannot enable if it's already in unavailable state if (m_enableState == esriExtensionState.esriESUnavailable) { throw new COMException("Cannot enable extension"); } //Determine if state can be changed esriExtensionState checkState = StateCheck(true); m_enableState = checkState; MessageBox.Show("Enabled"); CheckToolbarValidity(); SetupEvents(); } else if (requestState == 0 || requestState == esriExtensionState.esriESDisabled) { //Determine if state can be changed esriExtensionState checkState = StateCheck(false); if (checkState != m_enableState) m_enableState = checkState; MessageBox.Show("Disabled"); UnloadCustomizations(); //Remove event m_mapEvents.ItemAdded -= new IActiveViewEvents_ItemAddedEventHandler(OnItemAdded); } } } #endregion /// <summary> /// Determine extension state /// </summary> /// <param name="requestEnable">true if to enable; false to disable</param> private esriExtensionState StateCheck(bool requestEnable) { //TODO: Replace with advanced extension state checking if needed //Turn on or off extension directly if (requestEnable) return esriExtensionState.esriESEnabled; else return esriExtensionState.esriESDisabled; } #region IPersistVariant Members public UID ID { get { UID typeID = new UIDClass(); typeID.Value = GetType().GUID.ToString("B"); return typeID; } } public void Load(IVariantStream Stream) { //TODO: Load persisted data from document stream Marshal.ReleaseComObject(Stream); } public void Save(IVariantStream Stream) { //TODO: Save extension related data to document stream Marshal.ReleaseComObject(Stream); } #endregion private void SetupEvents() { // Make sure we're dealing with ArcMap if (m_application.Document.Parent is IMxApplication) { m_mxDocument = m_application.Document as IMxDocument; m_mapEvents = m_mxDocument.FocusMap as IActiveViewEvents_Event; m_mapEvents.ItemAdded += new IActiveViewEvents_ItemAddedEventHandler(OnItemAdded); m_mapStatusEvents = m_application.Document.Parent as IApplicationStatusEvents_Event; m_mapStatusEvents.Initialized += new IApplicationStatusEvents_InitializedEventHandler(OnInitialized); } } // Called when the framework is fully initialized // After this event fires, it is safe to make UI customizations void OnInitialized() { CheckToolbarValidity(); MessageBox.Show("Initialized"); } void OnItemAdded(object Item) { MessageBox.Show("Item Added"); IFeatureLayer pFeatureLayer; if (Item is IFeatureLayer) { pFeatureLayer = Item as IFeatureLayer; MessageBox.Show("Layer name: " + pFeatureLayer.Name); } } private void CheckToolbarValidity() { // Wait for framework to initialize before making ui customizations // Check framework initialization flag if (!m_appStatus.Initialized) return; // Make sure the extension is enabled if (m_enableState != esriExtensionState.esriESEnabled) return; // Perform the customization LoadCustomizations(); } private void LoadCustomizations() { } private void UnloadCustomizations() { } } }
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.