Hello everyone,
Sometimes when designing, I forget to run my important macros. Therefore, I came up with an idea and started researching: when finishing a drawing, I want a macro named Last.swp to run automatically when closing the part file. Can I do this, and do you have an example?
I found the “DestroyNotify2 of PartDoc” code but couldn’t apply it. There could be another code as well; it doesn’t have to be specifically this one for me.
Also, I can’t add anything to the path section of the SolidWorks shortcut because it’s a company computer, and some things are restricted .
Yes, it could be done. You need to catch the DestroyNotify2 of AssemblyDoc, PartDoc and DrawingDoc and call the SldWorks::RunMacro2 from the event handler.
You can’t really create a macro to do this. You will just shift the problem because you will have to remember to run a macro every time you start SOLIDWORKS so that it can listen for the Destroy event and this macro would have to be pretty complicated because it has to keep track of every document you open and close. This is not a novice level programming task. You could potentially add a macro feature to your template files that would set up the event handlers, but that too isn’t really a beginner level programming task. The best way to do this would be to create a SOLIDWORKS add-in, which is programmatically even more complicated.