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
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
RE: Easy API question
thread559-178764: VB code to tell if SolidWorks is installed on a computer: VB code to tell if SolidWorks is installed on a computer
Ken
RE: Easy API question
CODE
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
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
{
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.");
}
}
}