×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Easy API question

Easy API question

Easy API question

(OP)
  Just can't seem to get it to work.  I want to test to see if there is an currently running session of solidworks. On the API help SW page it says to use the "GetObject" command but doesn't give the syntax.

Here's what I want:

  debug.print "Look for active SW session."
Look for a session line

If session found then
  debug.print "Open SW session found."
  msgbox "Although not required it is advised that you close all active sessions of SolidWorks."
else
  debug.print "No SW sessions found"
end if

RE: Easy API question

GetObject is not a member of the SolidWorks API.  If you'll google GetObject you should be able to find plenty of syntax help.

RE: Easy API question

(OP)
Actually this is what I ended up using.  Thanks to both of you though.

 

CODE

Function IsAppRunning(ByVal sAppName) As Boolean
Dim oApp As Object

On Error Resume Next

Set oApp = GetObject(, sAppName)

If Not oApp Is Nothing Then
    Set oApp = Nothing
    IsAppRunning = True
End If

End Function

RE: Easy API question

Another way to do this is to get a list of processes that are running. This is useful if you want to check if multiple processes of the same application are running. This can happen quite easily in SolidWorks if you are not careful with object instantiation.

Below is the code in C# to do this. VB would be very similar (note: the 'log' function is part of the 'log4net' logger):

CODE

public class SWControl
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(ModuleAssembler));
        public void SWCleanup()
        {

            Process[] swRunning = Process.GetProcessesByName("SLDWORKS");
            Process swProcess;
            int swProcesses = swRunning.Length;
            if (swProcesses > 0)
            {
                log.Debug(swProcesses.ToString() + " SolidWorks processes running.");
                for (int i = 0; i < swProcesses; i++)
                {
                    swProcess = swRunning[i];
                    swProcess.Kill();
                }
                int killed = swProcesses;
                log.Debug(killed.ToString() + " SolidWorks processes killed.");
            }
        }
    }

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources