2 Replies Latest reply on Jun 10, 2014 12:21 AM by Greg Rupp

    Example of DocEvents

    Greg Rupp

      Does anyone have any VB.net examples using DocEvents? I'm trying to figure out how to use DocEvents_FileSaveNotifyEventHandler for all three file types. Thanks!

        • Re: Example of DocEvents
          Artem Taturevych

          Check this code snippet. It is also suggested to unsubscribe from events once the object is not used:


          Dim swModel As ModelDoc2


          Public Sub main()


              swModel = swApp.ActiveDoc



          End Sub


          Sub AttachHandler(ByVal model As ModelDoc2)

              If model IsNot Nothing Then

                  Select Case model.GetType

                      Case swDocumentTypes_e.swDocPART

                          Dim part As PartDoc = model

                          AddHandler part.FileSaveNotify, AddressOf OnFileSave

                      Case swDocumentTypes_e.swDocASSEMBLY

                          Dim assm As AssemblyDoc = model

                          AddHandler assm.FileSaveNotify, AddressOf OnFileSave

                      Case swDocumentTypes_e.swDocDRAWING

                          Dim drw As DrawingDoc = model

                          AddHandler drw.FileSaveNotify, AddressOf OnFileSave

                  End Select


              End If

          End Sub


          Function OnFileSave(ByVal FileName As String) As Integer

              MsgBox("File Saved: " + FileName)

              Return 0

          End Function


          Public swApp As SldWorks


          Regards, Artem Taturevych | Snr. Developer | IC3D ANZ


          IC3DSteel – New Steel Solution for SolidWorks

          LinkedIn - SolidWorks API Group