Using SwAddin to Create a SolidWorks Add-In
You can create a SolidWorks add-in using the ISwAddin
object instead of using a SolidWorks
add-in wizard.
When you use the ISwAddin object to create a SolidWorks add-in, the
add-in must include some specific functionality and code. It is also important
to understand what the SolidWorks software does for the add-in. Click
a link to read that section.
What does the add-in have to do?
The add-in DLL must be created as a COM Server and it must:
Implement a co-creatable object that supports
SwAddin.
Call regsvr32 during installation. Register the
add-in CLSID in HKEY_LOCAL_MACHINE\SOFTWARE\SolidWorks\AddIns and set
the following registry keys:
Default to 1 or 0, where 1 enables the add-in in the add-in
manager so that it loads when the user starts the SolidWorks software.
Description to a text description of the add-in that is displayed
in the add-in manager.
Title to a text title of the description that is displayed in
the add-in manager.
Define event handlers as needed.
In its implementation of ISwAddin::ConnectToSW,
the add-in can:
Call ISldWorks::SetAddinCallbackInfo
and pass the instance handle of the add-in and the object that supports
the callback methods. The SolidWorks software holds onto this object and
makes callbacks.
Call ISldWorks::AddMenuItem3
and pass the callback method associated with the menu item.
Call ISldWorks::AddToolbar4
and pass the callback method associated with the toolbar button.
Back to top
What does the SolidWorks software do?
When the end-user starts the SolidWorks software, it:
Checks the registry for add-ins.
Creates an object associated with the CLSID of
the add-in.
Performs a QueryInterface on the add-in looking
for the SwAddin object.
Calls ISwAddin::ConnectToSW
and passes a pointer to the SolidWorks session and the add-in ID.
When the user closes the SolidWorks software or disables an add-in in
the add-in Manager, the SolidWorks software:
Calls ISwAddin::DisconnectFromSW,
providing the add-in an opportunity for cleanup.
Destroys the object it created with the add-in
CLSID.
If the end-user disables an add-in in the add-in manager, the SolidWorks
software does not reload the next time the SolidWorks software starts.
If the end-user closes the SolidWorks software with an add-in enabled,
the SolidWorks software reloads the add-in the next time it starts.
Back to top
To learn more about add-ins and their menu items and toolbars: