Hello Mr. JelteDeJong
I did the same thing on vb.net, but it does not work anymore! Please take a look at my code!
Many thanks Sir!
Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Namespace TTF
<ProgIdAttribute("TTF.StandardAddInServer"),
GuidAttribute(g_simpleAddInClientID)>
Public Class StandardAddInServer
Implements Inventor.ApplicationAddInServer
'*********************************************************************************
'* The two declarations below are related to adding buttons to Inventor's UI.
'* They can be deleted if this add-in doesn't have a UI and only runs in the
'* background handling events.
'*********************************************************************************
' Declaration of the object for the UserInterfaceEvents to be able to handle
' if the user resets the ribbon so the button can be added back in.
Private WithEvents m_uiEvents As UserInterfaceEvents
Private WithEvents m_onDocumentChangeEvents As ApplicationEvents
' Declaration of the button definition with events to handle the click event.
' For additional commands this declaration along with other sections of code
' that apply to the button can be duplicated from this example.
#Region "ApplicationAddInServer Members"
' 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. However, with the introduction of the ribbon this argument is always true.
Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate
Try
' Initialize AddIn members.
g_inventorApplication = addInSiteObject.Application
' Connect to the user-interface events to handle a ribbon reset.
m_uiEvents = g_inventorApplication.UserInterfaceManager.UserInterfaceEvents
m_onDocumentChangeEvents = g_inventorApplication.ApplicationEvents
'*********************************************************************************
'* The remaining code in this Sub is all for adding the add-in into Inventor's UI.
'* It can be deleted if this add-in doesn't have a UI and only runs in the
'* background handling events.
'*********************************************************************************
' Create the button definition using the CreateButtonDefinition function to simplify this step.
' Add to the user interface, if it's the first time.
' If this add-in doesn't have a UI but runs in the background listening
' to events, you can delete this.
If firstTime Then
AddToUserInterface()
End If
Catch ex As Exception
MsgBox("Unexpected failure in the activation of the add-in ""TTF""" & vbCrLf & vbCrLf & ex.Message)
End Try
End Sub
' 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.
Public Sub Deactivate() Implements Inventor.ApplicationAddInServer.Deactivate
' Release objects.
m_uiEvents = Nothing
m_onDocumentChangeEvents = Nothing
g_inventorApplication = Nothing
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
End Sub
' 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.
' Typically it's not used, like in this case, and returns Nothing.
Public ReadOnly Property Automation() As Object Implements Inventor.ApplicationAddInServer.Automation
Get
Return Nothing
End Get
End Property
' Note:this method is now obsolete, you should use the
' ControlDefinition functionality for implementing commands.
Public Sub ExecuteCommand(ByVal commandID As Integer) Implements Inventor.ApplicationAddInServer.ExecuteCommand
' Not used.
End Sub
Private Sub m_onDocumentChangeEvents_OnDocumentChange(ByVal DocumentObject As Document,
ByVal BeforeOrAfter As EventTimingEnum,
ByVal ReasonsForChange As CommandTypesEnum,
ByVal Context As NameValueMap,
ByRef HandlingCode As HandlingCodeEnum) Handles m_onDocumentChangeEvents.OnDocumentChange
If BeforeOrAfter = EventTimingEnum.kAfter Then
MsgBox("OnDocumentChange")
End If
End Sub
#End Region
#Region "User interface definition"
' Adds whatever is needed by this add-in to the user-interface. This is
' called when the add-in loaded and also if the user interface is reset.
Private Sub AddToUserInterface()
' This sample code illustrates creating a button on a new panel of the Tools tab of
' the Part ribbon. You'll need to change this to create the UI that your add-in needs.
End Sub
Private Sub m_uiEvents_OnResetRibbonInterface(Context As NameValueMap) Handles m_uiEvents.OnResetRibbonInterface
' The ribbon was reset, so add back the add-ins user-interface.
AddToUserInterface()
End Sub
#End Region
End Class
End Namespace
Public Module Globals
' Inventor application object.
Public g_inventorApplication As Inventor.Application
' The unique ID for this add-in. If this add-in is copied to create a new add-in
' you need to update this ID along with the ID in the .manifest file, the .addin file
' and create a new ID for the typelib GUID in AssemblyInfo.vb
Public Const g_simpleAddInClientID As String = "45065451-f806-4680-8d84-4d2166b2b77a"
Public Const g_addInClientID As String = "{" & g_simpleAddInClientID & "}"
End Module