Page 1 of 1

if swapp is nothing.....

Posted: Wed Sep 22, 2021 2:08 pm
by Hansjoerg
hello all,

for a new macro project I searched the net for some code snippets.

In one of the references I have found a query whose sense I do not understand.

'check if application is open
if swapp is nothing then
msgbox "to execute the macro, swx must be open"
.....

what the query checked i still understand, but does that make sense with a swp macro at all? can the case occur at all?

A macro in swp format can only be executed via the corresponding function in swx, as far as I know you can't even run the macro editor without swx active, so starting the macro via the editor without swx active is also out of the question.
Why do i need this query then?

Re: if swapp is nothing.....

Posted: Wed Sep 22, 2021 3:19 pm
by Tom G
Maybe it crashed before completing? Otherwise, I have no idea there.

Re: if swapp is nothing.....

Posted: Wed Sep 22, 2021 3:34 pm
by SPerman
Since those files are VB6/VBA code, I assume it could be launched from other applications. I think you would have to put effort into making such a thing happen, but in theory it could be done.

Re: if swapp is nothing.....

Posted: Wed Sep 22, 2021 3:35 pm
by AlexLachance
swp is not strictly prohibited to SolidWorks, but I'm not sure why one would try to run the macro anywhere else then SW

Re: if swapp is nothing.....

Posted: Thu Sep 23, 2021 11:27 am
by HerrTick
Perfectly valid safety check. Not only does SW need to be running, but the code needs a valid SW application object. If that object ("swApp") gets disconnected somehow, then all of the code will not run.