Hi,
Please find the Application Add In event:
Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Namespace InventorAddIn2
<ProgIdAttribute("InventorAddIn2.StandardAddInServer"), _
GuidAttribute("78ee7c88-8b32-4af9-801b-3d2925c7b66c")> _
Public Class StandardAddInServer
Implements Inventor.ApplicationAddInServer
' Inventor application object.
Private m_inventorApplication As Inventor.Application
Private m_ClientID As String
'Application events
Private WithEvents m_inventorApplicationEvents As ApplicationEvents
#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
' 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))
m_inventorApplicationEvents = m_inventorApplication.ApplicationEvents
' TODO: Add ApplicationAddInServer.Activate implementation.
' e.g. event initialization, command creation etc.
SetupUserInterface(addInSiteObject, firstTime, m_ClientID)
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
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)
End Sub
Private Sub m_inventorApplicationEvents_OnSaveDocument(DocumentObject As _Document, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles m_inventorApplicationEvents.OnSaveDocument
If BeforeOrAfter = EventTimingEnum.kBefore Then
MsgBox("before")
End If
If BeforeOrAfter = EventTimingEnum.kAfter Then
MsgBox("after")
End If
End Sub
End Class
End Namespace