跳到主要内容

How to Create Stand-Alone (exe) Applications with SOLIDWORKS API

In this article, I will discuss two common methods to connect to a SOLIDWORKS instance using COM-compatible programming languages such as C#, VB.NET, C++, and Visual Basic 6, to leverage the SOLIDWORKS API.

Here are optional detailed explanations about these methods. Please follow the links below to see articles demonstrating how to create sample projects and connect to a SOLIDWORKS instance:

Method A - Activator and ProgId

Connect by creating an instance identified by Program Identified (progid) or globally unique COM Class Identifier (CLSID)

SOLIDWORKS has two types of program identifiers: version-independent and version-specific.

Program identifiers are registered in the Windows registry:

Class identifiers in Windows registry{ width=640 }

In the example above, the program identifier for SldWorks.Application.23 corresponds to the COM class identifier {D66FBAAE-4150-402F-8581-75D1652D696A}.

More information about this object, such as the type library class identifier and the COM server location (i.e., the path to sldworks.exe), can be found in the registry branch associated with the class identifier, i.e., HKEY_CLASSES_ROOT\CLSID{D66FBAAE-4150-402F-8581-75D1652D696A}.

Prog Ids in Windows registry{ width=640 }

The version-independent program identifier is the same for all versions of SOLIDWORKS and is equal to "SldWorks.Application".

If using a version-specific program identifier, the revision number needs to be specified after the program identifier, i.e., "SldWorks.Application.RevisionNumber". Refer to the table below for a list of SOLIDWORKS versions and their revision numbers:

VersionRevision Number
SOLIDWORKS 200513
SOLIDWORKS 200614
SOLIDWORKS 200715
SOLIDWORKS 200816
SOLIDWORKS 200917
SOLIDWORKS 201018
SOLIDWORKS 201119
SOLIDWORKS 201220
SOLIDWORKS 201321
SOLIDWORKS 201422
SOLIDWORKS 201523
SOLIDWORKS 201624
SOLIDWORKS 201725
SOLIDWORKS 201826
SOLIDWORKS 201927
SOLIDWORKS 202028
SOLIDWORKS 202129
SOLIDWORKS 202230

The revision number of the SOLIDWORKS session can be obtained using the ISldWorks::RevisionNumber method. The returned value is a string in the format 25.1.0, where the first number is the revision number.

There are some limitations when using this method:

  • It is not possible to predict whether this method will connect to a running SOLIDWORKS instance or create a new instance.
  • It is not possible to specify which running SOLIDWORKS session to connect to (e.g., when multiple SOLIDWORKS sessions are open).
  • If a new session is created by running this method, the session is by default invisible and started with the /embed flag. This means the session starts in a lightweight manner and does not load any add-ins. This is designed to allow embedding the OLE object in third-party applications such as Microsoft Office.

SOLIDWORKS part document OLE object in Excel{ width=400 }

  • It is not possible to create multiple active SOLIDWORKS sessions.

Method B - Running Object Table (ROT)

Connect by querying COM instances from the Running Object Table (ROT)

When a COM server creates an object instance, it creates an identifier for that instance and registers it in the Running Object Table (ROT). The ROT enables inter-process communication with third-party applications by allowing objects to be looked up from running processes using the Windows API GetRunningObjectTable.

Here is an example of a running object table with multiple registered COM objects:

!{00024505-0014-0000-C000-000000000046}

!Microsoft Visual Studio Telemetry:11004

!{31F45B04-7198-45ED-A13F-F224A4A1686A}

SolidWorks_PID_15212

!VisualStudio.DTE.14.0:16144

  • Using this method, it is possible to connect to any SOLIDWORKS session from its process ID.
  • The desired number of sessions can be created by starting new SOLIDWORKS instances (e.g., by using the shell or start process API).

If the SOLIDWORKS application and the stand-alone application run with different levels of privileges (e.g., one running as an administrator and the other not), it may not be possible to successfully retrieve objects from the ROT. Run them with the same user identity to enable communication.

Please follow the links at the beginning of the article for detailed guides and code examples on how to connect to a SOLIDWORKS instance.