Collapse Getting StartedGetting Started
Expand Types of SOLIDWORKS API ApplicationsTypes of SOLIDWORKS API Applications
Expand SOLIDWORKS API Object Model and Class HierarchySOLIDWORKS API Object Model and Class Hierarchy
Collapse Programming with the SOLIDWORKS APIProgramming with the SOLIDWORKS API
Expand Add-insAdd-ins
API Dependent on SOLIDWORKS Being Visible
Attributes Imported from ACIS SAT Files
Block Definitions and Block Instances
Bodies in Body Folders
Bounding Box and Note Text
COM vs. Dispatch
CommandManager and CommandGroups
Components, Configurations, and Suppression States
Compound Note
ComVisibleAttribute in VB.NET and C# Macros and Add-ins
Controls, Visual Basic 6.0, and Windows XP
Default Paths
Drawing Views and Model Entities
Early and Late Binding
Expand EventsEvents
Features of Components
Helper Functions
Hole Wizard Features and Objects
IDispatch Object Arrays as Input in .NET
Implementation Guidelines
Import and Export File Options
In-process Methods
Instantiate ActiveX Controls as Tabs
Interface Pointers
ISafeArrayUtility Interface Overview
Keystrokes and Accelerator Keys
Library Features and Objects
Lightweight Components
Line Attributes for View::GetPolyLinesAndCurves
Line Weights
Long vs. Integer
Expand Macro FeaturesMacro Features
Mass Properties
Expand Multibody PartsMultibody Parts
Option Explicit Statement
Expand Packing and Unpacking Double Arrays and Integer PairsPacking and Unpacking Double Arrays and Integer Pairs
Partition Rollback and API Handles
Persistent Reference IDs
Presentation Transforms
Expand PropertyManager PagesPropertyManager Pages
.NET Interop Assemblies
Quick Tips and Bubble ToolTips
Return Values
Expand SafeArraysSafeArrays
Selection Criteria
Selection Lists
Selections that Define Features
Setup Project to Distribute SOLIDWORKS Add-in
Smart Pointers
Sorting Tables
STL Container Classes and Smart Pointers
Suspend Automatic Rebuilds
Sweep Features and SweepFeatureData Objects
System Options and Document Properties
Tessellation and Edges
Third-party Data in SOLIDWORKS Files
Thread Features and ThreadFeatureData Objects
Tracking IDs
Expand Type LibrariesType Libraries
Unmanaged C++ and C++/CLI Code
Examples and Projects
Expand SOLIDWORKS PDM Professional API HelpSOLIDWORKS PDM Professional API Help
Expand FeatureWorks API HelpFeatureWorks API Help
Expand SOLIDWORKS Document Manager API HelpSOLIDWORKS Document Manager API Help
Expand SOLIDWORKS Simulation API HelpSOLIDWORKS Simulation API Help
Expand SOLIDWORKS Sustainability API HelpSOLIDWORKS Sustainability API Help
Expand SOLIDWORKS Utilities API HelpSOLIDWORKS Utilities API Help
Expand eDrawings API HelpeDrawings API Help
Hide Table of Contents

Accessing SOLIDWORKS Add-in Objects

There are two types of add-ins that you can use with SOLIDWORKS:

To see the SOLIDWORKS add-ins that you are licensed to use, select Tools > Add-Ins from the SOLIDWORKS menu. The Add-Ins dialog lists SOLIDWORKS add-ins at the top and Other add-ins at the bottom. To get the functionality of a SOLIDWORKS add-in or to use its APIs, you must load it either from the Add-Ins dialog or programmatically. In the Add-Ins dialog, select the check box next to the add-in of interest and click OK. To load the add-in programmatically, call ISldWorks::LoadAddIn, passing in the add-in name.

Accessing SOLIDWORKS Add-in Objects

After loading a SOLIDWORKS add-in either through the user interface or by calling ISldWorks::LoadAddIn, in order to use its APIs, you must first access the add-in's API object by calling ISldWorks::GetAddInObject. The following table lists the four SOLIDWORKS add-ins whose add-in objects can be retrieved by calling ISldWorks::GetAddInObject with either a GUID, a version-independent ProgID or, in two cases, a version-specific ProgID:

Add-in Version-independent ProgID Version-specific ProgID (for SW2018) GUID location in the Windows Registry (regedit.exe)... Add-in object returned by ISldWorks::GetAddInObject
FeatureWorks "FeatureWorks.FeatureWorksApp" Not applicable - use version-independent ProgID or GUID HKEY_LOCAL_MACHINE\SOFTWARE\SolidWorks\Applications\FeatureWorks IFeatureWorksApp
SOLIDWORKS Design Checker "SWDesignChecker.SWDesignCheck" "SWDesignChecker.SWDesignCheck.2018" Search for SOLIDWORKS Design Checker in data fields of HKEY_LOCAL_MACHINE\SOFTWARE\SolidWorks\SOLIDWORKS 2018\Addins\. (The GUID is highlighted in the left panel when the add-in name is found in the right panel.) ISWDesignCheck
SOLIDWORKS Simulation "SldWorks.Simulation" "SldWorks.Simulation.11" HKEY_LOCAL_MACHINE\SOFTWARE\SolidWorks\SOLIDWORKS 2018\Applications\SOLIDWORKS Simulation ICwAddincallback (access ICosmosWorks through ICwAddinCallback::CosmosWorks)
SOLIDWORKS Utilities "Utilities.UtilitiesApp" Not applicable - use version-independent ProgID or GUID HKEY_LOCAL_MACHINE\SOFTWARE\SolidWorks\Applications\SOLIDWORKS Utilities IUtilities

Version-Independent ProgID

The version-independent ProgID of a SOLIDWORKS add-in remains unchanged from one version of SOLIDWORKS to the next.

Some SOLIDWORKS add-ins (e.g., FeatureWorks and SOLIDWORKS Utilities) use only version-independent ProgIDs. As a result, the version-independent ProgID can be used successfully from any version of SOLIDWORKS installed, as long as the add-in, itself, is loaded.

Other SOLIDWORKS add-ins (e.g., SOLIDWORKS Simulation and SOLIDWORKS Design Checker) use either version-specific or version-independent ProgIDs. When you have multiple SOLIDWORKS installations, the version-independent ProgID can only be used successfully from the latest version of SOLIDWORKS. If you have multiple SOLIDWORKS installations and are running one of the earlier versions, passing in the version-independent ProgID results in type mismatches and a failure to access the SOLIDWORKS add-in object. In that case, you must pass in the version-specific ProgID to successfully access the SOLIDWORKS add-in object.

Version-Specific ProgID

The version-specific ProgID of a SOLIDWORKS add-in changes from one version of SOLIDWORKS to the next.

When you have multiple SOLIDWORKS installations, for two SOLIDWORKS add-ins (SOLIDWORKS Simulation and SOLIDWORKS Design Checker), passing in the version-specific ProgID succeeds regardless of whether you are running the latest version or an earlier version.

The most reliable method for accessing SOLIDWORKS add-in objects, when you do not have strict control over the installation history of your system, is to first call ISldWorks::RevisionNumber to identify the version of SOLIDWORKS running and then use that information to calculate at runtime the SOLIDWORKS-compatible version-specific ProgID for the add-in.

The calculation of the version-specific ProgID differs between SOLIDWORKS Simulation and SOLIDWORKS Design Checker. In the calculations below, SOLIDWORKS_major_version_number is the leftmost two digits in the string returned by ISldWorks::RevisionNumber. For example, if ISldWorks::RevisionNumber returns "26.0.0", then SOLIDWORKS_major_version_number is 26, and the minor version decimal number is 0.0.

SOLIDWORKS Simulation Version-Specific ProgID

Specify ProgID as "Sldworks.Simulation.nn", where:

  • nn = SOLIDWORKS_major_version_number - 15
SOLIDWORKS Design Checker Version-Specific ProgID

Specify ProgID as "SWDesignChecker.SWDesignCheck.nnnn", where:

  • nnnn = SOLIDWORKS_major_version_number + 1992


Specify Clsid with a GUID in curly braces, "{GUID}", or ISldWorks::GetAddInObject will interpret it as a ProgID.

Code Snippets

The following code snippets demonstrate, in four languages, how to calculate the SOLIDWORKS-compatible version-specific ProgID for the SOLIDWORKS Simulation add-in and use it in ISldWorks::GetAddInObject to retrieve the correct SOLIDWORKS Simulation add-in object.


Option Explicit

Sub main()

   Dim SwApp As SldWorks.SldWorks
   Dim COSMOSWORKS As Object
   Dim COSMOSObject As Object
   Dim swVersion As Long
   Dim cwVersion As Long
   Dim cwProgID As String


   'Connect to SOLIDWORKS

    If SwApp Is Nothing Then Set SwApp = Application.SldWorks

   'Determine host SOLIDWORKS major version
    swVersion  = Left(SwApp.RevisionNumber, 2)

   'Calculate the version-specific ProgID of the Simulation add-in that is compatible with this version of SOLIDWORKS
    cwVersion  =  swVersion  -  15
    cwProgID  =  "SldWorks.Simulation." & cwVersion
    Debug.Print (cwProgID)

   'Get the SOLIDWORKS Simulation object

    Set COSMOSObject = SwApp.GetAddInObject(cwProgID)
    If COSMOSObject Is Nothing Then ErrorMsg SwApp, "COSMOSObject object not found", True

    If COSMOSWORKS Is Nothing Then ErrorMsg SwApp, "COSMOSWORKS object not found", True

   'Open the active document and use the COSMOSWORKS API


End Sub



Partial Class SolidWorksMacro
    Public Sub main()
        Dim COSMOSWORKS As Object
        Dim COSMOSObject As Object
 swVersion As Integer
        Dim cwVersion As Integer
        Dim cwProgID As String


        'Determine host SOLIDWORKS major version
        swVersion = Convert.ToInt32(swApp.RevisionNumber().Substring(0, 2))

        'Calculate the version-specific ProgID of the Simulation add-in that is compatible with this version of SOLIDWORKS
        cwVersion = swVersion - 15
        cwProgID = String.Format("SldWorks.Simulation.{0}", cwVersion)
        'Get the SOLIDWORKS Simulation object
        COSMOSObject = swApp.GetAddInObject(cwProgID)
        If COSMOSObject Is Nothing Then ErrorMsg(swApp, "COSMOSObject object not found"True)
        COSMOSWORKS = COSMOSObject.CosmosWorks
        If COSMOSWORKS Is Nothing Then ErrorMsg(swApp, "COSMOSWORKS object not found"True)
        'Open the active document and use the COSMOSWORKS API


    End Sub
    ''' <summary>
    ''' The SldWorks swApp variable is pre-assigned for you.
    ''' </summary>
    Public swApp As SldWorks
End Class



partial class SolidWorksMacro
        public void Main()
            dynamic COSMOSWORKS = default(dynamic);
            dynamic COSMOSObject = default(dynamic);


            // Determine host SOLIDWORKS major version
            int swVersion = Convert.ToInt32(swApp.RevisionNumber().Substring(0, 2));

            // Calculate the version-specific ProgID of the Simulation add-in that is compatible with this version of SOLIDWORKS
            int cwVersion = swVersion - 15;
            String cwProgID = String.Format("SldWorks.Simulation.{0}", cwVersion);
            // Get the SOLIDWORKS Simulation object 
            COSMOSObject = swApp.GetAddInObject(cwProgID);
            if (COSMOSObject == null) ErrorMsg(swApp, "COSMOSObject object not found"true);
            COSMOSWORKS = COSMOSObject.CosmosWorks;
            if (COSMOSWORKS == null) ErrorMsg(swApp, "COSMOSWORKS object not found"true);
            // Open the active document and use the COSMOSWORKS API



        /// <summary> 
        /// The SldWorks swApp variable is pre-assigned for you. 
        /// </summary> 
        public SldWorks swApp;

Unmanaged C++ COM

#include "stdafx.h" 
#include <string>
#import "sldworks.tlb" raw_interfaces_only, raw_native_types, no_namespace, named_guids  // SOLIDWORKS type library
#import "swconst.tlb" raw_interfaces_only, raw_native_types, no_namespace, named_guids   // SOLIDWORKS constants type library
#import "cosworks.tlb" raw_interfaces_only, raw_native_types, no_namespace, named_guids   // SOLIDWORKS Simulation type library
using namespace std;
int _tmain(int argc_TCHARargv[])

    // Initialize COM
    // Do this before using ATL smart pointers so that 
    // COM is available
    // Use a block so that the smart pointers are destructed when 
    // the scope of this block is exited
        // Use ATL smart pointers
        CComPtr<ISldWorks>  pSwApp;
        CComPtr<ICosmosWorks> pCOSMOSWORKS;
        CComPtr<IDispatch> pCOSMOSDispatch;
        CComPtr<ICwAddincallback> pCOSMOSObject;
        CComPtr<IDispatch> pDispatchSafeArray = NULL;
        CComPtr<ISafeArrayUtility> pSwSafeArray = NULL;
        HRESULT hres;
        if (pSwApp.CoCreateInstance(__uuidof(SldWorks), NULLCLSCTX_LOCAL_SERVER) != S_OK) {
        if (pSwApp.CoCreateInstance(__uuidof(ICosmosWorks), NULLCLSCTX_LOCAL_SERVER) != S_OK) {
        if (pSwApp.CoCreateInstance(__uuidof(IDispatch), NULLCLSCTX_LOCAL_SERVER) != S_OK) {
        if (pSwApp.CoCreateInstance(__uuidof(ICwAddincallback), NULLCLSCTX_LOCAL_SERVER) != S_OK) {

        hres = pSwApp->GetSafeArrayUtility(&pDispatchSafeArray);
        hres = pDispatchSafeArray.QueryInterface<ISafeArrayUtility>(&pSwSafeArray);
        // Determine host SOLIDWORKS major version
        CComBSTR bstrNum;
        std::string strNum;
        char *buffer;
        strNum = W2A(bstrNum);
        long m_swMajNum = strtol(strNum.c_str(), &buffer, 10);
        // Calculate the version-specific ProgID of the Simulation add-in that is compatible with this version of SOLIDWORKS
        long cwVersion;
        cwVersion = m_swMajNum - 15;
        CComBSTR cwProgID;
        CComBSTR strVersion;
        wchar_t temp_str[11];
        _itow_s(cwVersion, temp_str, 10);
        strVersion = SysAllocString(temp_str);
        cwProgID = OLESTR("SldWorks.Simulation.");
        strVersion = cwProgID.Append(strVersion);
        // Get the SOLIDWORKS Simulation object 
        pSwApp->GetAddInObject(strVersion, &pCOSMOSDispatch);

        if (pCOSMOSDispatch == NULL) {
            CComBSTR msg;
            msg = (OLESTR("COSMOSObject object not found: "));
            long res;
            pSwApp->SendMsgToUser2(msg, 0, 0, &res);
        hres = pCOSMOSDispatch->QueryInterface(__uuidof(CwAddincallback),(void**)&pCOSMOSObject);

        if (pCOSMOSWORKS == NULL) {
            CComBSTR msg;
            msg = (OLESTR("COSMOSWORKS object not found: "));
            long res;
            pSwApp->SendMsgToUser2(msg, 0, 0, &res);
        // Open the active document and use the COSMOSWORKS API

        . . .


    // ATL smart pointers are destructed so that all COM objects 
    // held on to are released
    // Shut down COM because you no longer need it
    // Stop COM


See Accessing SOLIDWORKS Objects.

Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

Subject:   Feedback on Help Topics
Page:   Accessing SOLIDWORKS Add-in Objects
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:


We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again

Web Help Content Version: API Help (English only) 2018 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.