Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy API question

Status
Not open for further replies.

ScottWisker

Mechanical
Jan 31, 2007
15
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
 
Replies continue below

Recommended for you

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

thread559-178764: VB code to tell if SolidWorks is installed on a computer

Ken
 
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
 
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.");
            }
        }
    }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor