I am trying to write a macro for SoliWorks 2016 that will automatically run when a drawing is opened. Most of the information I have found uses an equation triggered approach to accomplish this. However, that technique no longer works (http://www.cadsharp.com/blog/equation-triggered-macros ). I found an approach using "event listeners" on http://www.javelin-tech.com/blog/2013/03/event-listeners-solidworks-macro which had a nice video to walk through it. I followed their approach, but it gave me errors. I am guessing this is due to using SW2016 instead of SW2013. I made some changes to get it to run, but it does not create the message window it is supposed to.
Here is my code for the Module I named Auto_open1:
Dim swApp As Object
Dim AutoOpen As NewDocOpen
Sub main()
Set swApp = Application.SldWorks
Set AutoOpen = New NewDocOpen
End Sub
Here is my code for the Classs Module I named NewDocOpen:
Private WithEvents swApp As SldWorks.SldWorks
Private Sub Class_Initialize()
End Sub
Private Function swApp_FileOpenNotify(ByVal FileName As String) As Long
Dim msgString As String
Dim msgStatus As Integer
msgString = "File " & FileName & "was opened."
'swApp.SendMsgToUser msgString
msgStatus = swApp.SendMsgToUser2(msgString, swMbInformation, swMbOk)
End Function
Note: When I did not get a message window using SendMsgToUser (which is obsolete according to the Help), I used SendMsgToUser2 instead, but still got no message window.
I am not a programmer. My experience is as EE and have done some scripting in Tcl and PERL. I have not done any Visual Basic or OOP.... In looking at the code I don't see anything calling the swApp_FileOpenNotify Function, and stepping through with the Debugger, it never gets executed. But things worked without in SW20013 according to the video noted above.