AnsweredAssumed Answered

VB.NET 2008 Notification Problem

Question asked by Tony Szuta on Aug 24, 2009
Latest reply on Aug 25, 2009 by Tony Szuta

Josh Brady had posted a macro that monitors document notifications. I am able to modify his macro to fit most of my needs, but I would like to port it to VB.NET. I would like to take his idea and mold it to fit here where I work. The code listed below is working fine except for the notification portion. For the life of me, I can't understand the new 2009 API help. If someone could look over my modified code and possibly let me know what I am missing, I would appreciate it. I have never attempted this notification stuff before.

 

[VB.NET CODE START]

Public Class Form1

 

    Dim WithEvents swApp As SldWorks.SldWorks
    Dim WithEvents swAssy As SldWorks.AssemblyDoc
    Dim WithEvents swDwg As SldWorks.DrawingDoc
    Dim WithEvents swPart As SldWorks.PartDoc
    Dim swDoc As SldWorks.ModelDoc2

 

    Public Enum swDocumentTypes_e
        swDocNONE = 0
        swDocPART = 1
        swDocASSEMBLY = 2
        swDocDRAWING = 3
    End Enum

 

    Private Function swApp_ActiveDocChangeNotify() As Integer
        Report("Active Document Change")
        DocEventRefresh()
        UpdateForm()
    End Function

 

    Private Function swAssy_RegenNotify() As Integer
        Report("Assembly Regen")
        UpdateForm()
    End Function

 

    Private Function swDwg_RegenNotify() As Integer
        Report("Drawing Regen")
        UpdateForm()
    End Function

 

    Private Function swPart_RegenNotify() As Integer
        Report("Part Regen")
        UpdateForm()
    End Function

 

    Sub DocEventRefresh()
        swDoc = swApp.ActiveDoc
        Me.Text = swDoc.GetTitle

 

        Select Case swDoc.GetType
            Case swDocumentTypes_e.swDocPART
                swPart = swDoc
                swDwg = Nothing
                swAssy = Nothing
            Case swDocumentTypes_e.swDocDRAWING
                swPart = Nothing
                swDwg = swDoc
                swAssy = Nothing
            Case swDocumentTypes_e.swDocASSEMBLY
                swPart = Nothing
                swDwg = Nothing
                swAssy = swDoc
            Case Else
                swPart = Nothing
                swDwg = Nothing
                swAssy = Nothing
        End Select

 

    End Sub

 

    Sub UpdateForm()
        Report("Form Updated")
    End Sub

 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        swApp = GetObject(, "SldWorks.Application")
        Report("Connected To Current SolidWorks Session")
        Call DocEventRefresh()
        UpdateForm()
    End Sub

 

    Public Sub Report(ByRef NotificationText As String)
        Report1.Items.Add(NotificationText)
        Report1.SelectedIndex = Report1.Items.Count - 1
    End Sub
End Class

[VB.NET CODE END]

Outcomes