Registering the add-in

In order to register the SOLIDWORKS add-in with SwEx framework it is required:

  • Create a public class which inherits the SwAddInEx class
  • Make this class com visible by adding the System.Runtime.InteropServices.ComVisibleAttribute attribute
  • Add the AutoRegisterAttribute attribute to add the required information to the registry.
[AutoRegister("Export Components (C#)", "Exports selected component to neutral format", true)]
[ComVisible(true)]
public class SwExportComponentAddIn : SwAddInEx
{
}

OnConnect

This function is called within the ConnectToSw entry point. Override this function to initialize the add-in.

Return the result of the initialization. Return true to indicate that the initialization is successful. Return ‘false’ to cancel the loading of the add-in.

This override should be used to validate license (return false if the validation is failed), add command manager, task pane views, initialize events manager, etc.

OnDisconnect

This function is called within the DisconnectFromSw function. Use the function to release all resources. You do not need to release the com pointers to SOLIDWORKS or command manager as those will be automatically released by SwEx framework.

Accessing SOLIDWORKS application objects

SwEx framework provides the access to the following objects which are preassigned by the framework

App property

Pointer to SOLIDWORKS application

AddInCookie property

Add-in id

CmdMgr property

Pointer to command manager

Unregistering add-in

Add-in will be automatically removed and all COM objects unregistered when project is cleaned in Visual Studio