Get Process ID of SOLIDWORKS Session Example (C#)
This example shows how to get and verify the process ID of the current
SOLIDWORKS session.
//--------------------------------------------------------
// Preconditions:
// 1. One SOLIDWORKS session is running.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. The process ID of the SOLIDWORKS session is
// printed to the Immediate window.
// 2. To verify, open a Command Prompt window, type TASKLIST, and
// locate sldworks.exe in the Image Name column and its
// process ID in the corresponding PID column.
// 3. Exit the Command Prompt window.
//----------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
namespace GetProcessIDCSharp.csproj
{
public partial class SolidWorksMacro
{
public void Main()
{
// Print the current SOLIDWORKS session's PID to the
// Immediate window
Debug.Print("SOLIDWORKS process ID: " + swApp.GetProcessID());
}
/// <summary>
/// The SldWorks swApp variable is pre-assigned for you.
/// </summary>
public SldWorks swApp;
}
}