I use it without button maybe that is already the case.
Maybe it is easier that you send me the add in files complete so that I can add my code to it.
Otherwise you can use my code:
Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Imports System.Windows.Forms
Namespace KnoorsInventorToolsDockableWindow
<ProgIdAttribute("######.StandardAddInServer"), _
GuidAttribute("#####")> _
Public Class StandardAddInServer
Implements Inventor.ApplicationAddInServer
' Inventor application object.
Private m_inventorApplication As Inventor.Application
Private m_ClientID As String
Public m_Form As StartFormulier
Public My_DockableWindow As DockableWindow
Private WithEvents oInteraction As InteractionEvents
Private WithEvents oUserInputEvents As UserInputEvents
Private WithEvents m_AppEvents As Inventor.ApplicationEvents
Private WithEvents oUserInterfaceEvents As UserInterfaceEvents
Private WithEvents oSelectEvents As SelectEvents
Private WithEvents oMouseEvents As MouseEvents
Private WithEvents oKeyPress As KeyboardEvents
Private WithEvents oAppEvents As ApplicationEvents
Private WithEvents oModelingEvents As ModelingEvents
Private WithEvents oDocEvents As DocumentEvents
Private WithEvents oDockableWindowsEvents As DockableWindowsEvents
Private WithEvents oDockableWindowsSinkEvents As DockableWindowsEventsSink_Event
Private WithEvents M_LargeButtonDefinition As ButtonDefinition
Private WithEvents M_SmallButtonDefinition As ButtonDefinition
#Region "ApplicationAddInServer Members"
Public ReadOnly Property InventorApplication As Inventor.Application
Get
Return m_inventorApplication
End Get
End Property
Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate
'MsgBox("sdfsfdsf")
' 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
m_ClientID = AddInGuid(GetType(StandardAddInServer))
SetupUserInterface(addInSiteObject, firstTime, m_ClientID)
My_DockableWindow = m_inventorApplication.UserInterfaceManager.DockableWindows.Add(m_ClientID, m_ClientID, "Kit (Bom Info)")
My_DockableWindow.Visible = False
m_Form = New StartFormulier(m_inventorApplication, My_DockableWindow)
My_DockableWindow.AddChild(m_Form.Handle.ToInt64)
My_DockableWindow.DockingState = DockingStateEnum.kDockLastKnown
My_DockableWindow.Width = 208
My_DockableWindow.SetMinimumSize(200, 208)
My_DockableWindow.Visible = False
m_AppEvents = m_inventorApplication.ApplicationEvents
oUserInputEvents = m_inventorApplication.CommandManager.UserInputEvents
oUserInterfaceEvents = m_inventorApplication.UserInterfaceManager.UserInterfaceEvents
oInteraction = m_inventorApplication.CommandManager.CreateInteractionEvents
oAppEvents = m_inventorApplication.ApplicationEvents
oModelingEvents = m_inventorApplication.ModelingEvents
oDockableWindowsEvents = m_inventorApplication.UserInterfaceManager.DockableWindows.Events
oDockableWindowsSinkEvents = m_inventorApplication.UserInterfaceManager.DockableWindows.Events
oInteraction.Start()
oSelectEvents = oInteraction.SelectEvents
oMouseEvents = oInteraction.MouseEvents
oKeyPress = oInteraction.KeyboardEvents
End Sub
Public Sub Deactivate() Implements Inventor.ApplicationAddInServer.Deactivate
' This method is called by Inventor when the AddIn is unloaded.
' The AddIn will be unloaded either manually by the user or
' when the Inventor session is terminated.
' TODO: Add ApplicationAddInServer.Deactivate implementation
' Release objects.
Marshal.ReleaseComObject(m_inventorApplication)
m_inventorApplication = Nothing
m_Form = Nothing
My_DockableWindow.DockingState = DockingStateEnum.kDockLastKnown
My_DockableWindow = Nothing
m_AppEvents = Nothing
oUserInputEvents = Nothing
oUserInterfaceEvents = Nothing
oInteraction = Nothing
oAppEvents = Nothing
oModelingEvents = Nothing
oDockableWindowsEvents = Nothing
oDockableWindowsSinkEvents = Nothing
oSelectEvents = Nothing
oMouseEvents = Nothing
oKeyPress = Nothing
System.GC.WaitForPendingFinalizers()
System.GC.Collect()
End Sub
Public ReadOnly Property Automation() As Object Implements Inventor.ApplicationAddInServer.Automation
' This property is provided to allow the AddIn to expose an API
' of its own to other programs. Typically, this would be done by
' implementing the AddIn's API interface in a class and returning
' that class object through this property.
Get
Return Nothing
End Get
End Property
Public Sub ExecuteCommand(ByVal commandID As Integer) Implements Inventor.ApplicationAddInServer.ExecuteCommand
' Note:this method is now obsolete, you should use the
' ControlDefinition functionality for implementing commands.
End Sub
#End Region
Public Shared ReadOnly Property AddInGuid(ByVal t As Type) As String
Get
Dim guid As String = ""
Try
Dim customAttributes() As Object = t.GetCustomAttributes(GetType(GuidAttribute), False)
Dim guidAttribute As GuidAttribute = CType(customAttributes(0), GuidAttribute)
guid = "{" + guidAttribute.Value.ToString() + "}"
Finally
AddInGuid = guid
End Try
End Get
End Property
Public Sub SetupUserInterface(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean, ClientID As String)
If firstTime And addInSiteObject.Application.UserInterfaceManager.InterfaceStyle = InterfaceStyleEnum.kRibbonInterface Then
ElseIf firstTime And addInSiteObject.Application.UserInterfaceManager.InterfaceStyle = InterfaceStyleEnum.kClassicInterface Then
MsgBox("classic Interface")
Else
MsgBox("unknown Interface")
End If
End Sub
Private Sub m_AppEvents_OnActivateDocument(ByVal DocumentObject As Inventor._Document, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles m_AppEvents.OnActivateDocument
'ONLY DEFINE THE LAYOUT OF THE FORM HERE
'DON'T READ ANY PROPERTIES SINCE THE ADD IN IS BASED ON THE ACTIVE EDIT DOCUMENT.
If BeforeOrAfter = EventTimingEnum.kAfter Then
If DocumentObject.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
m_Form.GbGenSpecProps.Hide()
m_Form.GbCompSpecProps.Hide()
m_Form.GbKeys.Hide()
MdlPropertyValuesFillIn.PropertyValuesFillIn(m_inventorApplication, m_Form)
MdlInitializeStartFormulier.InitializeStartFormulier(m_Form, DocumentObject)
ElseIf DocumentObject.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
m_Form.GbGenSpecProps.Show()
m_Form.GbCompSpecProps.Show()
m_Form.GbKeys.Hide()
ElseIf DocumentObject.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
m_Form.GbGenSpecProps.Show()
m_Form.GbCompSpecProps.Show()
m_Form.GbKeys.Show()
End If
m_Form.Show()
End If
End Sub
Private Sub m_AppEvents_OnDocumentChange(DocumentObject As _Document, BeforeOrAfter As EventTimingEnum, ReasonsForChange As CommandTypesEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles m_AppEvents.OnDocumentChange
If BeforeOrAfter = EventTimingEnum.kAfter Then
If ReasonsForChange = 1 Then
If DocumentObject.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
Try
MdlListModelKeys.ListModelKeys(DocumentObject, m_Form)
Catch ex As Exception
End Try
End If
End If
MdlPropertyValuesFillIn.PropertyValuesFillIn(m_inventorApplication, m_Form)
End If
End Sub
Private Sub m_AppEvents_OnNewEditObject(EditObject As Object, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles m_AppEvents.OnNewEditObject
Dim DocumentObject As Document = Nothing
Try
DocumentObject = TryCast(EditObject, Document)
Catch ex As Exception
End Try
If BeforeOrAfter = EventTimingEnum.kAfter Then
If DocumentObject.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
m_Form.GbGenSpecProps.Hide()
m_Form.GbCompSpecProps.Hide()
m_Form.GbKeys.Hide()
ElseIf DocumentObject.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
m_Form.GbGenSpecProps.Show()
m_Form.GbCompSpecProps.Show()
m_Form.GbKeys.Hide()
ElseIf DocumentObject.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
m_Form.GbGenSpecProps.Show()
m_Form.GbCompSpecProps.Show()
m_Form.GbKeys.Show()
Try
MdlListModelKeys.ListModelKeys(DocumentObject, m_Form)
Catch ex As Exception
End Try
End If
MdlPropertyValuesFillIn.PropertyValuesFillIn(m_inventorApplication, m_Form)
MdlInitializeStartFormulier.InitializeStartFormulier(m_Form, DocumentObject)
My_DockableWindow.Visible = True
End If
End Sub
Private Sub m_AppEvents_OnSaveDocument(DocumentObject As _Document, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles m_AppEvents.OnSaveDocument
If DocumentObject.FileSaveCounter = 1 Then
If BeforeOrAfter = EventTimingEnum.kAfter Then
If DocumentObject.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
m_Form.GbGenSpecProps.Hide()
m_Form.GbCompSpecProps.Hide()
m_Form.GbKeys.Hide()
ElseIf DocumentObject.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
m_Form.GbGenSpecProps.Show()
m_Form.GbCompSpecProps.Show()
m_Form.GbKeys.Hide()
ElseIf DocumentObject.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
m_Form.GbGenSpecProps.Show()
m_Form.GbCompSpecProps.Show()
m_Form.GbKeys.Show()
MdlListModelKeys.ListModelKeys(DocumentObject, m_Form)
End If
MdlPropertyValuesFillIn.PropertyValuesFillIn(m_inventorApplication, m_Form)
MdlInitializeStartFormulier.InitializeStartFormulier(m_Form, DocumentObject)
m_Form.Show()
End If
End If
'
End Sub
Private Sub m_AppEvents_OnCloseDocument(DocumentObject As _Document, FullDocumentName As String, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles m_AppEvents.OnCloseDocument
If BeforeOrAfter = EventTimingEnum.kAfter Then
If m_inventorApplication.ActiveDocument Is Nothing Then
My_DockableWindow.Visible = False
Else
End If
End If
End Sub
Private Sub m_AppEvents_OnActivateView(ViewObject As Inventor.View, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles m_AppEvents.OnActivateView
If BeforeOrAfter = EventTimingEnum.kAfter Then
m_Form.Height = My_DockableWindow.Height
End If
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class
End Namespace