public void Deactivate() { // Release objects. if (_activeProjectType == MultiUserModeEnum.kVaultMode) { UnSubscribeEvents(); } _applicationEvents.OnActiveProjectChanged -= ApplicationEvents_OnActiveProjectChanged; _userInputEvents = null; _dockableWindowsEvents = null; _applicationEvents = null; _vaultAddin = null; _myVaultBrowserButton = null; _myVaultBrowser = null; _hwndDic = null; Hook.Clear(); Marshal.ReleaseComObject(_inventorApplication); _inventorApplication = null; GC.Collect(); GC.WaitForPendingFinalizers(); }
/// <summary>Initializes the <see cref="DockableWindowWrapper"/>.</summary> /// <param name="addInSite">The ApplicationAddInSite object supplied by Inventor.</param> /// <param name="form">The managed form to add to the DockableWindow.</param> /// <param name="initialDockingState">The initial docking state of the DockableWindow /// if it is created for the first time.</param> internal DockableWindowWrapper( Inventor.ApplicationAddInSite addInSite, Form form, Inventor.DockingStateEnum initialDockingState) { System.Diagnostics.Debug.Assert(addInSite != null && form != null); _form = form; // Set up the parameters. string clientId = addInSite.Parent.ClientId; string internalName = _form.GetType().FullName + "." + form.Name; string title = _form.Text; // We don't want the border to show since the form will be docked inside the DockableWindow. _form.FormBorderStyle = FormBorderStyle.None; // Retrieve or create the dockable window. try { dockableWindow = addInSite.Application.UserInterfaceManager.DockableWindows[internalName]; } catch { dockableWindow = addInSite.Application.UserInterfaceManager.DockableWindows.Add( clientId, internalName, title); } // Set the minimum size of the dockable window. System.Drawing.Size minimumSize = form.MinimumSize; if (!minimumSize.IsEmpty) { dockableWindow.SetMinimumSize(minimumSize.Height, minimumSize.Width); } // Set the initial docking state of the DockableWindow if it is not remembered by Inventor. if (initialDockingState != default(Inventor.DockingStateEnum)) // && !dockableWindow.IsCustomized) { dockableWindow.DockingState = initialDockingState; } // Set initial state to invisible. dockableWindow.Visible = false; // Listen for events. _form.HandleCreated += new EventHandler(OnHandleCreated); _form.VisibleChanged += new EventHandler(OnVisibleChanged); _dockableWindowsEvents = addInSite.Application.UserInterfaceManager.DockableWindows.Events; _dockableWindowsEvents.OnHide += new DockableWindowsEventsSink_OnHideEventHandler(DockableWindowsEvents_OnHide); }
/// <summary>Initializes the <see cref="DockableWindowWrapper"/>.</summary> /// <param name="addInSite">The ApplicationAddInSite object supplied by Inventor.</param> /// <param name="form">The managed form to add to the DockableWindow.</param> /// <param name="initialDockingState">The initial docking state of the DockableWindow /// if it is created for the first time.</param> internal DockableWindowWrapper( Inventor.ApplicationAddInSite addInSite, Form form, Inventor.DockingStateEnum initialDockingState) { System.Diagnostics.Debug.Assert(addInSite != null && form != null); _form = form; // Set up the parameters. string clientId = addInSite.Parent.ClientId; string internalName = _form.GetType().FullName + "." + form.Name; string title = _form.Text; // We don't want the border to show since the form will be docked inside the DockableWindow. _form.FormBorderStyle = FormBorderStyle.None; // Retrieve or create the dockable window. try { dockableWindow = addInSite.Application.UserInterfaceManager.DockableWindows[internalName]; } catch { dockableWindow = addInSite.Application.UserInterfaceManager.DockableWindows.Add( clientId, internalName, title); } // Set the minimum size of the dockable window. System.Drawing.Size minimumSize = form.MinimumSize; if (!minimumSize.IsEmpty) dockableWindow.SetMinimumSize(minimumSize.Height, minimumSize.Width); // Set the initial docking state of the DockableWindow if it is not remembered by Inventor. if (initialDockingState != default(Inventor.DockingStateEnum)) // && !dockableWindow.IsCustomized) dockableWindow.DockingState = initialDockingState; // Set initial state to invisible. dockableWindow.Visible = false; // Listen for events. _form.HandleCreated += new EventHandler(OnHandleCreated); _form.VisibleChanged += new EventHandler(OnVisibleChanged); _dockableWindowsEvents = addInSite.Application.UserInterfaceManager.DockableWindows.Events; _dockableWindowsEvents.OnHide += new DockableWindowsEventsSink_OnHideEventHandler(DockableWindowsEvents_OnHide); }
public void Activate(ApplicationAddInSite addInSiteObject, bool firstTime) { // This method is called by Inventor when it loads the addin. // The AddInSiteObject provides access to the Inventor Application object. // The FirstTime flag indicates if the addin is loaded for the first time. // Initialize AddIn members. _inventorApplication = addInSiteObject.Application; try { _vaultAddin = _inventorApplication.ApplicationAddIns.ItemById["{48b682bc-42e6-4953-84c5-3d253b52e77b}"]; } catch { MessageBox.Show(Resources.VaultAddinNotFound, @"MyVaultBrowser", MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } _applicationEvents = _inventorApplication.ApplicationEvents; _dockableWindowsEvents = _inventorApplication.UserInterfaceManager.DockableWindows.Events; _userInputEvents = _inventorApplication.CommandManager.UserInputEvents; _activeProjectType = _inventorApplication.DesignProjectManager.ActiveDesignProject.ProjectType; _hwndDic = new Dictionary <Document, IntPtr>(); Hook.Initialize(this); _myVaultBrowser = _inventorApplication.UserInterfaceManager.DockableWindows.Add("{ffbbb57a-07f3-4d5c-97b0-e8e302247c7a}", "myvaultbrowser", "MyVaultBrowser"); _myVaultBrowser.Title = "Vault"; _myVaultBrowser.ShowTitleBar = true; _myVaultBrowser.DisabledDockingStates = DockingStateEnum.kDockBottom | DockingStateEnum.kDockTop; _myVaultBrowser.SetMinimumSize(200, 150); _myVaultBrowserButton = _inventorApplication.CommandManager.ControlDefinitions.AddButtonDefinition( "MyVaultBrowser", "myvaultbrowserbutton", CommandTypesEnum.kQueryOnlyCmdType, "{ffbbb57a-07f3-4d5c-97b0-e8e302247c7a}", "Toggle MyVaultBrowser", "", "", "", ButtonDisplayEnum.kNoTextWithIcon); _myVaultBrowserButton.OnExecute += _myVaultBrowserButton_OnExecute; if (!_myVaultBrowser.IsCustomized) { _myVaultBrowser.DockingState = DockingStateEnum.kDockRight; _myVaultBrowser.Visible = true; } _applicationEvents.OnActiveProjectChanged += ApplicationEvents_OnActiveProjectChanged; if (_inventorApplication.Ready) { if (_activeProjectType == MultiUserModeEnum.kVaultMode) { TryLoadVaultAddin(); } } else { _applicationEvents.OnReady += ApplicationEvents_OnReady; } }
public void Deactivate() { // Release objects. if (_activeProjectType == MultiUserModeEnum.kVaultMode) UnSubscribeEvents(); _applicationEvents.OnActiveProjectChanged -= ApplicationEvents_OnActiveProjectChanged; _userInterfaceEvents.OnResetShortcuts -= UserInterfaceEvents_OnResetShortcuts; _userInterfaceEvents = null; _dockableWindowsEvents = null; _applicationEvents = null; _vaultAddin = null; _myVaultBrowser = null; _hwndDic = null; Hook.Clear(); Marshal.ReleaseComObject(_inventorApplication); _inventorApplication = null; GC.Collect(); GC.WaitForPendingFinalizers(); }
public void Activate(ApplicationAddInSite addInSiteObject, bool firstTime) { // This method is called by Inventor when it loads the addin. // The AddInSiteObject provides access to the Inventor Application object. // The FirstTime flag indicates if the addin is loaded for the first time. // Initialize AddIn members. _inventorApplication = addInSiteObject.Application; try { _vaultAddin = _inventorApplication.ApplicationAddIns.ItemById["{48b682bc-42e6-4953-84c5-3d253b52e77b}"]; } catch { MessageBox.Show(Resources.VaultAddinNotFound, @"MyVaultBrowser", MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } _applicationEvents = _inventorApplication.ApplicationEvents; _dockableWindowsEvents = _inventorApplication.UserInterfaceManager.DockableWindows.Events; _userInterfaceEvents = _inventorApplication.UserInterfaceManager.UserInterfaceEvents; _activeProjectType = _inventorApplication.DesignProjectManager.ActiveDesignProject.ProjectType; _hwndDic = new Dictionary<Document, IntPtr>(); Hook.Initialize(this); _myVaultBrowser = _inventorApplication.UserInterfaceManager.DockableWindows.Add("{ffbbb57a-07f3-4d5c-97b0-e8e302247c7a}", "myvaultbrowser", "MyVaultBrowser"); _myVaultBrowser.Title = "Vault"; _myVaultBrowser.ShowTitleBar = true; _myVaultBrowser.DisabledDockingStates = DockingStateEnum.kDockBottom | DockingStateEnum.kDockTop; _myVaultBrowser.SetMinimumSize(200, 150); SetShortCut(); if (!_myVaultBrowser.IsCustomized) { _myVaultBrowser.DockingState = DockingStateEnum.kDockRight; _myVaultBrowser.Visible = true; } _applicationEvents.OnActiveProjectChanged += ApplicationEvents_OnActiveProjectChanged; _userInterfaceEvents.OnResetShortcuts += UserInterfaceEvents_OnResetShortcuts; if (_inventorApplication.Ready) { if (_activeProjectType == MultiUserModeEnum.kVaultMode) TryLoadVaultAddin(); } else _applicationEvents.OnReady += ApplicationEvents_OnReady; }