Community
I am writing an AddIn that adds a button to a command bar. Each time I run the AddIn it adds another button. How do I either clear the command bar or add the button so that it is not duplicated each time I debug it?
Activate function
Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate ' 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. m_inventorApplication = addInSiteObject.Application 'Get the ClassID for this add-in and save it in a 'member variable to use whenever a ClientID is needed m_ClientID = "{7ff8d131-439f-469e-9a66-4531beab12c4}" 'Create a new toolbar and make it visible If firstTime Then GetOrAddCommandBar() End If ' TODO: Add ApplicationAddInServer.Activate implementation. ' e.g. event initialization, command creation etc. End Sub
GetOrAddCommandBar function
Private Sub GetOrAddCommandBar() 'Variable declarations Dim cmdBar As Inventor.CommandBar Dim smallicon As stdole.IPictureDisp Dim largeicon As stdole.IPictureDisp 'Set command bar to nothing cmdBar = Nothing 'Attempt to get the existing command bar Try cmdBar = m_inventorApplication.UserInterfaceManager.CommandBars.Item("CP AddIns") Catch ex As Exception End Try 'Check to see if the existing command bar was found. If cmdBar Is Nothing Then 'Create a new command bar cmdBar = m_inventorApplication.UserInterfaceManager.CommandBars.Add("CP AddIns", "CP AddIns") End If 'Convert icon smallicon = PictureDispConverter.ToIPictureDisp(My.Resources.cmdButtonIcon) largeicon = PictureDispConverter.ToIPictureDisp(My.Resources.cmdButtonIcon) 'Create button definition m_cmdButtonDef = m_inventorApplication.CommandManager.ControlDefinitions.AddButtonDefinition("Print A Size", "PrintASize", _ Inventor.CommandTypesEnum.kQueryOnlyCmdType, , "Print A Size", "Print A Size", smallicon, largeicon, ButtonDisplayEnum.kDisplayTextInLearningMode) 'Add the button cmdBar.Controls.AddButton(m_cmdButtonDef) 'Make the command bar visible cmdBar.Visible = True End Sub
Also, how do I force the AddIn to use the 16x16 icon instead of the 32x32 one?
Found my problem. I was adding the button regardless if the command bar was found or not. Programming error.