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 .
How to Run Macros While Closing the Solidworks)
Re: How to Run Macros While Closing the Solidworks)
This is an old post from the old forums.
https://forum.solidworks.com/thread/81373
https://forum.solidworks.com/thread/81373
Artem Taturevych
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.
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
Re: How to Run Macros While Closing the Solidworks)
Yes, I saw that page too, but I couldn't apply it. I quoted "DestroyNotify2 of PartDoc" from there. But I couldn't do it, I didn't fully understand.SPerman wrote: ↑Tue Mar 26, 2024 9:24 am This is an old post from the old forums.
https://forum.solidworks.com/thread/81373
Re: How to Run Macros While Closing the Solidworks)
@artem is on these forums. Maybe he will reply and elaborate.
ETA: He was on the forums. It looks like he hasn't been active in over a year.
ETA: He was on the forums. It looks like he hasn't been active in over a year.
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
Re: How to Run Macros While Closing the Solidworks)
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.senuba wrote: ↑Tue Mar 26, 2024 9:16 am 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 .
Re: How to Run Macros While Closing the Solidworks)
JSculley wrote: ↑Tue Mar 26, 2024 11:00 am 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.
I understand. Thank you. I'll consider another way then.