1 Reply Latest reply on Jan 5, 2014 1:39 AM by Matthew aDAMS

    Error Handeling to fix debug issue w/ multi sessions of SW

    Matthew aDAMS

      HI all,

       

      I want to thank you guys for the wealth of information on the form it has been very helpful.

       

      Here is what is going on... I have had some user complain that the sometimes get a Debug error when running a marco that I have written.  I have traced down the problem, I know what I want to do to fix it I just can't find the right calls.

       

      Problem:

           When two sessions for Solidworks are running and the macro is run there is a debug error on the line of code the put a UI window on top of all other windows. I can post some of the code if needed but the code works fine if there is only one session of Solidworks running.

       

      Solution:

           Add error handling that we check the number of solidworks applications running and if it is more than one return an error message of "Don't be Stupid".  I know the simplest thing to do is get on the users about having more than one session running.

       

      Can anyone help out here?  I have done some searching but I'm not really sure how to search this.

       

      Thanks all and Happy New Years!

       

      Running SW2012 SP4.0 X64 on Win7

        • Re: Error Handeling to fix debug issue w/ multi sessions of SW
          Matthew aDAMS

          I just got it.  Here is the answer to close out the thread.  I changed this to return an error box and stop the marco before it tries to launch the UI window.  If anyone has questions me know.

           

          Option Explicit

           

          Dim strComputer As String

          Dim objWMI As Object

          Dim proc As Object

           

          Sub IsSWRunning()

              strComputer = "."

              Set objWMI = GetObject("winmgmts:" _

              & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

              Set proc = objWMI.ExecQuery _

              ("Select * from Win32_Process Where Name = 'SLDworks.exe'")

              If proc.Count = 0 Then

                  MsgBox "SLDworks.exe is not running."

              Else

                  MsgBox proc.Count & " instances of SLDworks.exe is running."

              End If

          End Sub