KEVOS
ArticlesServicesCase studiesAboutContact
ArticlesServicesCase studiesAboutContact
← ArticlesSolidWorks API: Add-in Architecture and the Integration ModelEngineering · Computing & SoftwareLesson 1/10← PrevNext →
GuidePublished 4 Aug 2026Updated 12 Aug 20268 min readBy Kevin JoginSolidWorks APICAD automationCOM interopadd-in development
On this page

Ask about this page

KEVOS AISolidWorks API: Add-in Architecture and the Integration Model

KEVOS knowledge first · trusted web sources when needed

KEVOS® Knowledge Library · SolidWorks API Add-in Development

Add-in Architecture and the SolidWorks Integration Model

What actually makes an add-in an add-in — the interface contract, the COM registration it depends on, and the load-to-release lifecycle that every well-behaved SolidWorks® extension must honour.

  • Doc № KL-ENG-COMP-001
  • Engineering › Computers
  • Part 01 of 10
  • 9 min read
  • Updated 2026-08-04

01Executive summary

A SolidWorks add-in is not defined by what it looks like to the user. It is defined by a contract. A managed class earns the name add-in when three conditions hold simultaneously: it implements the ISwAddin interface, it correctly handles the connect and disconnect calls that interface demands, and it is registered with COM so the operating system can hand it back to SolidWorks on request. Everything that fails any one of those three tests is, by definition, a stand-alone program — regardless of whether it drives SolidWorks, ships as a DLL, or looks integrated.

That definition matters commercially as well as technically. It determines whether your code runs inside the SolidWorks process or beside it, whether it can receive notifications, which API members are reachable, and how much installer engineering you will be signing up for. This page sets out the architecture before any code is written, because the decision is expensive to reverse.

3conditions that define an add-in
2interface members you must implement
1process shared with SolidWorks
2registry hives touched at registration

02The three-part definition

The interface contract is deliberately small. ISwAddin asks for two members and nothing else: one invoked when SolidWorks loads your assembly into memory, and one invoked when it unloads it. All of the apparent complexity of add-in development — menus, pages, notifications, installers — is built on top of that pair.

InterfaceISwAddin
bool ConnectToSW(object ThisSW, int Cookie)
bool DisconnectFromSW()
ThisSW
The live SolidWorks application object for the session that loaded you. Functionally identical to the application pointer used in a macro or stand-alone client; cast it to the interface type (ISldWorks) and hold it as a field.
Cookie
The session-unique identifier SolidWorks assigns to your add-in. It is the routing key for every callback and for acquiring the Command Manager. Store it; you cannot obtain it again later.
Return value
true tells SolidWorks the transition succeeded. Returning false from the connect call signals a failed load and should be reserved for genuine initialisation failure.

The second condition is COM registration. A managed class library is invisible to SolidWorks until the assembly is registered for COM interop and the class is marked visible with a stable GUID. The third condition is discovery: an entry under the SolidWorks add-ins registry key, named for that same GUID, so the application knows a candidate exists and can ask COM to produce it. Miss any one and you have a correctly compiled assembly that never loads.

Definition in practice

If a colleague describes their DLL as an add-in because it appears in a toolbar, ask whether it implements ISwAddin. Toolbars can be created from a stand-alone client too. The interface, the connect and disconnect handling, and COM registration are the whole test.

03Load-to-release lifecycle

Understanding the order of events removes most of the mystery from add-in debugging. The sequence below runs on every SolidWorks session in which your add-in is enabled.

  1. Build timeAssembly compiled and registered

    The class library is compiled to a DLL. Registration for COM interop publishes the class under its GUID and runs your registration hook, which writes the SolidWorks discovery keys.

  2. Session startSolidWorks enumerates candidates

    SolidWorks reads its add-ins registry key, collects the GUIDs it finds and consults the per-user start-up key to decide which of them to load immediately rather than on demand.

  3. ActivationCOM instantiates the class

    The operating system resolves the GUID to your assembly, the runtime loads it into the SolidWorks process, and an instance of your add-in class is created.

  4. ConnectConnectToSW is called

    You receive the application object and the cookie. This is where you register callback routing, acquire the Command Manager, build menus and toolbars, and attach application-level event handlers.

  5. RuntimeCallbacks and notifications flow

    Menu clicks, page control events and document notifications are dispatched into your instance for as long as the add-in stays loaded.

  6. DisconnectDisconnectFromSW is called

    Triggered by the user unloading the add-in or by SolidWorks closing. Remove command groups, detach every event handler, close any open pages and release interop references.

  7. ReleaseReferences dropped and memory reclaimed

    Null every field holding a SolidWorks object and request collection so the runtime releases the underlying COM references promptly rather than at an arbitrary later point.

Teardown is not optional

Command groups that are not removed on disconnect stay in the SolidWorks menus and toolbars. When the user clicks one, the callback target no longer exists and the failure surfaces inside SolidWorks rather than inside your add-in. Treat the disconnect path as the mirror image of the connect path and build them together.

04The in-process model and what it buys you

An add-in is loaded by SolidWorks into the SolidWorks process and runs on the same thread. That single fact produces most of the practical differences between add-ins and stand-alone clients.

Consequence

Call overhead falls away

Method calls do not cross a process boundary, so marshalling cost is materially lower. On calculation-heavy work over an active model — traversals, repeated property reads, geometry queries — the difference compounds.

Consequence

The full API surface opens

A small set of members are only meaningful in-process, including preview and preview-bitmap operations. If your requirement touches them, the architecture decision is already made for you.

Consequence

Callbacks become available

Only a registered add-in can receive callbacks and notifications. A stand-alone client can poll, but it cannot be told that a document changed, a selection was made or a file was saved.

Consequence

Your faults become SolidWorks faults

An unhandled exception in your code executes inside the host process. Defensive error handling is not a nicety; it is the difference between a warning dialog and a lost modelling session.

Design rule

Because you share the host's process and thread, treat every callback body as if it were running inside SolidWorks itself — which it is. Keep them short, wrap anything that can throw, and push long-running work behind an explicit user action rather than an event.

05The object graph you will be working in

Almost every add-in resolves the same small set of root objects during connect, then reaches the rest of the model through them.

  • ISldWorksThe application root, handed to you as the connect parameter. Session settings, document creation, user messaging.
    • ICommandManagerAcquired with the cookie. Owns command groups, which in turn own the menu and toolbar items your add-in publishes.
    • IModelDoc2The active document. Its concrete type — part, assembly or drawing — determines which event interface and which feature set apply.
      • ISelectionMgrWhat the user currently has selected, and the typed object behind that selection.
      • Custom property setsThe document metadata most business logic actually reads and writes.
    • IPropertyManagerPage2A page hosted in the SolidWorks task panel, created through the application object and driven by a handler class you supply.
C# — minimal add-in skeletonIllustrative
[Guid("00000000-0000-0000-0000-000000000000"), ComVisible(true)]
[SwAddin(Title = "KEVOS Example",
         Description = "Demonstration add-in",
         LoadAtStartup = true)]
public class KevosAddin : ISwAddin
{
    private ISldWorks _sw;
    private int _cookie;

    public bool ConnectToSW(object ThisSW, int Cookie)
    {
        _sw = (ISldWorks)ThisSW;
        _cookie = Cookie;

        // Route callbacks back to this instance before anything
        // that can raise one is created.
        _sw.SetAddinCallbackInfo(0, this, _cookie);

        BuildCommands();
        AttachApplicationEvents();
        return true;
    }

    public bool DisconnectFromSW()
    {
        DetachApplicationEvents();
        RemoveCommands();

        _sw = null;
        GC.Collect();
        GC.WaitForPendingFinalizers();
        return true;
    }
}

06Cookies and callback routing

SolidWorks needs to know which object should receive the callbacks raised on your behalf. That association is established by a single call made during connect, before any command or page that could raise a callback exists.

MethodISldWorks.SetAddinCallbackInfo
void SetAddinCallbackInfo(int Reserved, object AddinObject, int Cookie)
Reserved
Passed as zero.
AddinObject
The instance that will receive callbacks — normally the add-in class itself, so that callback methods can be plain public methods on that class.
Cookie
The identifier handed to you in the connect call. It ties the registration to your specific add-in instance in this session.

Because callbacks are resolved by name at the point the user acts, not by delegate at the point the command is created, a mistyped callback name compiles cleanly and fails silently at runtime. This is one of the most common defects in first add-ins, and the reason for treating callback names as constants rather than string literals scattered through the command-building code.

07Releasing interop references

Interop objects hold references to unmanaged COM objects. Leaving them to be collected whenever the runtime feels like it produces the classic symptom set: SolidWorks refuses to close cleanly, an orphaned process lingers, or documents stay locked after the add-in unloads.

  1. Null the fields

    Set every field holding a SolidWorks type — application, model, component, page and control references — to null in the teardown path.

  2. Detach first

    Remove event handlers before nulling the object that raises them, otherwise the handler keeps the source alive.

  3. Force collection

    Request a collection so the release happens at a moment you choose rather than at an arbitrary later point in the host process.

  4. Verify on exit

    Close SolidWorks with the add-in loaded and confirm the process actually terminates. This single test catches most reference leaks.

08Quick reference

Add-in test
Implements ISwAddin + handles connect/disconnect + registered with COM. All three, or it is a stand-alone.
Interface members
ConnectToSW(object, int) and DisconnectFromSW(), both returning bool.
Assembly type
Class library (DLL). A stand-alone client is an executable.
Process model
In-process; same process and thread as the host application.
Discovery
Registry entry named for the class GUID under the SolidWorks add-ins key, plus a per-user start-up flag.
Callback routing
SetAddinCallbackInfo(0, this, Cookie), called during connect.
Teardown obligations
Detach events, remove command groups, close pages, null references, collect.

09Where this leads

Key takeaways

  1. An add-in is a contract, not a look. Implement ISwAddin, handle both lifecycle members, register with COM — or you have built something else.
  2. The cookie is issued once, during connect. It is the routing key for callbacks and the Command Manager, so capture it immediately.
  3. In-process execution buys speed, the full API surface and notifications; it costs you robustness margin, because your faults are the host's faults.
  4. Build the disconnect path at the same time as the connect path. Every acquisition should have a visible, symmetrical release.
  5. Reference discipline is verified, not assumed: if SolidWorks does not exit cleanly with your add-in loaded, you have a leak.

Continue in this pathway

  • Part 01Add-in architecture and the integration model
  • Part 02Development environment and project configuration
  • Part 03COM registration and add-in discovery
  • Part 04Command Manager, menus and toolbars
  • Part 05Property Manager Pages and the control model
  • Part 06Event and notification architecture
  • Part 07Add-in, stand-alone or hybrid
  • Part 08Planning, structure and debugging discipline
  • Part 09Deployment methods and installer engineering
  • Part 10Licensing, distribution and commercialisation

KEVOS® — Precision to Vision. Prepared by Kevin Jogin for the KEVOS® Knowledge Library. Interface names, enumerators and registry paths refer to the SolidWorks® API as published by Dassault Systèmes SolidWorks Corporation; SolidWorks® is their registered trademark. Code listings are original KEVOS® illustrations written to demonstrate the pattern under discussion and are supplied without warranty.

Continue learning

NEXT LESSON →SolidWorks API: Development Environment and Project ConfigurationGuide · Computing & SoftwareSolidWorks API: COM Registration and Add-in DiscoveryGuide · Computing & SoftwareSolidWorks API: Command Manager, Menus and ToolbarsGuide · Computing & SoftwareSolidWorks API: Property Manager Pages and the Control ModelGuide · Computing & Software
KEVOS · Engineering, manufacturing and project improvement
ArticlesServicesCase studiesAboutContact
© 2026 KEVOS®