Handle Events in AddIn



I'm trying to create an AddIn for SE.The Addin itself works.

But now I want to handle some Events by myselfe. For Example BeforeDocumentSave, AfterDocumentSave, and so on.  But the Events are not called.

Waht have I done wrong? Or does anyone have an example for me.

I'm using VS 2008 .NET (Visual Basic) and Solid Edge V20

Br Florian

Here my code:

Imports SolidEdgeFramework

Imports System.Runtime.InteropServices

Imports System.Windows.Forms



Public Class Connect

    Implements SolidEdgeFramework.ISolidEdgeAddIn, SolidEdgeFramework.ISEApplicationEvents


    Dim m_seApp As SolidEdgeFramework.Application

    Dim m_AddinInstance As SolidEdgeFramework.AddIn

    Dim WithEvents m_SeAppEvents As SolidEdgeFramework.DISEApplicationEvents_Event


#Region "ISolidEdgeAddIn Members"

    Public Sub OnConnection(ByVal Application As Object, ByVal ConnectMode As SolidEdgeFramework.SeConnectMode, ByVal AddInInstance As SolidEdgeFramework.AddIn) Implements SolidEdgeFramework.ISolidEdgeAddIn.OnConnection



            m_AddinInstance = AddInInstance

            m_seApp = CType(Application, SolidEdgeFramework.Application)

            m_SeAppEvents = CType(m_seApp.ApplicationEvents, SolidEdgeFramework.DISEApplicationEvents_Event)

        Catch ex As Exception


        End Try

    End Sub


    Public Sub OnConnectToEnvironment(ByVal EnvCatID As String, ByVal pEnvironmentDispatch As Object, ByVal bFirstTime As Boolean) Implements SolidEdgeFramework.ISolidEdgeAddIn.OnConnectToEnvironment


    End Sub


    Public Sub OnDisconnection(ByVal DisconnectMode As SolidEdgeFramework.SeDisconnectMode) Implements SolidEdgeFramework.ISolidEdgeAddIn.OnDisconnection


    End Sub


#End Region


#Region "ISEApplicationEvents Members"


    Public Sub AfterActiveDocumentChange(ByVal theDocument As Object) Implements SolidEdgeFramework.ISEApplicationEvents.AfterActiveDocumentChange


    End Sub


    Public Sub AfterCommandRun(ByVal theCommandID As Integer) Implements SolidEdgeFramework.ISEApplicationEvents.AfterCommandRun


    End Sub


    Public Sub AfterDocumentOpen(ByVal theDocument As Object) Implements SolidEdgeFramework.ISEApplicationEvents.AfterDocumentOpen


    End Sub


    Public Sub AfterDocumentPrint(ByVal theDocument As Object, ByVal hDC As Integer, ByRef ModelToDC As Double, ByRef Rect As Integer) Implements SolidEdgeFramework.ISEApplicationEvents.AfterDocumentPrint


    End Sub


    Public Sub AfterDocumentSave(ByVal theDocument As Object) Implements SolidEdgeFramework.ISEApplicationEvents.AfterDocumentSave


    End Sub


    Public Sub AfterEnvironmentActivate(ByVal theEnvironment As Object) Implements SolidEdgeFramework.ISEApplicationEvents.AfterEnvironmentActivate


    End Sub


    Public Sub AfterNewDocumentOpen(ByVal theDocument As Object) Implements SolidEdgeFramework.ISEApplicationEvents.AfterNewDocumentOpen


    End Sub


    Public Sub AfterNewWindow(ByVal theWindow As Object) Implements SolidEdgeFramework.ISEApplicationEvents.AfterNewWindow


    End Sub


    Public Sub AfterWindowActivate(ByVal theWindow As Object) Implements SolidEdgeFramework.ISEApplicationEvents.AfterWindowActivate


    End Sub


    Public Sub BeforeCommandRun(ByVal theCommandID As Integer) Implements SolidEdgeFramework.ISEApplicationEvents.BeforeCommandRun


    End Sub


    Public Sub BeforeDocumentClose(ByVal theDocument As Object) Implements SolidEdgeFramework.ISEApplicationEvents.BeforeDocumentClose


    End Sub


    Public Sub BeforeDocumentPrint(ByVal theDocument As Object, ByVal hDC As Integer, ByRef ModelToDC As Double, ByRef Rect As Integer) Implements SolidEdgeFramework.ISEApplicationEvents.BeforeDocumentPrint


    End Sub


    Public Sub BeforeDocumentSave(ByVal theDocument As Object) Implements SolidEdgeFramework.ISEApplicationEvents.BeforeDocumentSave


    End Sub


    Public Sub BeforeEnvironmentDeactivate(ByVal theEnvironment As Object) Implements SolidEdgeFramework.ISEApplicationEvents.BeforeEnvironmentDeactivate


    End Sub


    Public Sub BeforeQuit() Implements SolidEdgeFramework.ISEApplicationEvents.BeforeQuit


    End Sub


    Public Sub BeforeWindowDeactivate(ByVal theWindow As Object) Implements SolidEdgeFramework.ISEApplicationEvents.BeforeWindowDeactivate


    End Sub


#End Region


End Class





Posted by: Florian Tree
Post date: 9/10/2008 1:06:15 AM


RE: Handle Events in AddIn

I have the same problem


Posted by: nicolas garet
Post date: 6/4/2009 9:20:12 AM

RE: Handle Events in AddIn



I found very useful this resources

1. Jason Addin Wizard (Great tool Jason!)

2. C:\Program Files\Solid Edge ST\SDK\Samples\Addins\VB




Posted by: Massimo Magris
Post date: 6/4/2009 8:06:55 PM

RE: Handle Events in AddIn

Hi all,


Is there anybody have a solution for this problem?

While I try to make my addin, I ran into the same problem as Florian.

I try to catch the BeforeDocumentSave event, because my code is there.

Unfortunately nothing happens.


I have made some further investigations with Solid Edge Spy (with event spy). But the BeforeDocumentSave event has been fired.

That is what makes the problem strange.


Any help would be great.




Posted by: Mihály Hammer
Post date: 12/18/2010 4:56:06 AM

RE: Handle Events in AddIn

Hi all,


the code shown above is wrong. I see the declaration done correctly using WithEvents on declaring m_SeAppEvents:


Dim WithEvents m_SeAppEvents As SolidEdgeFramework.DISEApplicationEvents_Event


but i can't see anywhere handlers for the events to handle! And that's why the code can't work - no event handler no handling of events. What i see are just interface implementation procedures.


Instead of a procedure like this:


Public Sub BeforeDocumentSave(ByVal theDocument As Object) Implements SolidEdgeFramework.ISEApplicationEvents.BeforeDocumentSave


End Sub


there should be a procedure like this:


Private Sub m_SeAppEvents_BeforeDocumentSave(ByVal theDocument As Object) Handles m_SeAppEvents.BeforeDocumentSave


End Sub


By the way, Solid Edge ST3 comes with a complete new (complex) sample add-in written in VB.NET. You find it under the directory SDK\Samples\Addins\VB .NET. This sample uses an alternate way of defining handlers (due to observed problems) and also provides hooks for adding own dialogs in the edgebar etc. But this sample is a very good base for starting with your own add-in (read carefully all comments in there!).




Posted by: Wolfgang Kunert
Post date: 12/18/2010 10:11:17 PM

RE: Handle Events in AddIn



First of all thank you for your prompt answer.

I do not know (I am rather newby for SE or even VB programming) if it is necessary or not, but when hiting enter after the line "Implements SolidEdgeFramework.ISolidEdgeAddIn, SolidEdgeFramework.ISEApplicationEvents",

the developer drops all the bold subs automatically.

That is why I thought (and I think Florian, too), it is the way of catching the required event.


I will give a try for my addin with your suggestions.




Posted by: Mihály Hammer
Post date: 12/19/2010 12:31:48 AM

RE: Handle Events in AddIn

Hello Mihokjol,


the problem in the code shown is, that the class Connect not only implements the interface SolidEdgeFramework.ISolidEdgeAddIn, but also SolidEdgeFramework.ISEApplicationEvents. The latter is unnecessary and wrong. Visual Studio creates automatically stubs for all the methods of an interface a class declares to implement.



Posted by: Wolfgang Kunert
Post date: 12/19/2010 9:13:35 AM

RE: Handle Events in AddIn

A couple of notes. The "D"ISE..Events interfaces are IDispatch interfaces created for VB 4 back in the days when VB only worked with dispatch interfaces. I would not use it.


The VB.NET add-in sample delivered in the sdk does events this way:


Declare an object to handle the events in the add-in instance data:


' Set up to support Edge application events

Private pAppEvents As SolidEdgeFramework.ISEApplicationEvents_Event


connect to a specific event (usually in OnConnection)


AddHandler pAppEvents.AfterActiveDocumentChange, AddressOf AfterActiveDocumentChange


disconnect from the specific event (usually in Dispose method)


RemoveHandler pAppEvents.AfterActiveDocumentChange, AddressOf AfterActiveDocumentChange


and finally the method to handle the event:


Public Sub AfterActiveDocumentChange(ByVal theDocument As Object)

End Sub



Now quick - post before the site updates the page I am on and loses all my work! See the VB.NET sample ...


Posted by: R.D. Holland
Post date: 1/24/2011 8:03:10 AM