Table of Contents

Class AddinMaker

Namespace
Hymma.Solidworks.Addins
Assembly
Hymma.Solidworks.Addins.dll

Base class for creating SolidWorks add-ins. Inherit from this class and override GetUserInterFace() to define your add-in's user interface.

[ComVisible(true)]
public abstract class AddinMaker : ISwAddin
Inheritance
AddinMaker
Implements
ISwAddin
Inherited Members

Examples

Basic add-in implementation:

[Addin(title: "My Add-in",
       AddinIcon = "icon.png",
       Description = "My SolidWorks add-in",
       LoadAtStartup = true)]
[ComVisible(true)]
[Guid("YOUR-GUID-HERE")]
public class MyAddin : AddinMaker
{
    private ISldWorks _solidworks;

    public MyAddin()
    {
        // Subscribe to lifecycle events
        OnStart += (sender, e) => _solidworks = e.Solidworks;
        OnExit += (sender, e) => { /* cleanup */ };
    }

    public override AddinUserInterface GetUserInterFace()
    {
        return new AddinUserInterface
        {
            CommandTabs = new List<AddinCommandTab> { /* your tabs */ },
            IconsRootDir = new DirectoryInfo(@"C:\MyAddin\Icons")
        };
    }

    // Callback methods must be public and defined in this class
    public void MyButtonCallback() { /* handle click */ }
    public int MyEnableMethod() => _solidworks?.ActiveDoc != null ? 1 : 0;
}

Remarks

This class handles COM registration, connection to SolidWorks, and lifecycle management of your add-in. You must decorate your derived class with the following attributes:

Constructors

AddinMaker()

initial values will be saved to memory here.

protected AddinMaker()

Fields

_commandManager

command manager for this addin assigned by SOLIDWORKS

protected CommandManager _commandManager

Field Value

CommandManager

documentsEventsRepo

a collection of documents and their associated events

protected Hashtable documentsEventsRepo

Field Value

Hashtable

Methods

AddCommands(IEnumerable<AddinCommandTab>)

Adds commands to the addin

public void AddCommands(IEnumerable<AddinCommandTab> commandTabs)

Parameters

commandTabs IEnumerable<AddinCommandTab>

ConnectToSW(object, int)

SOLIDWORKS calls this method and assigns its params once addin is loaded

public bool ConnectToSW(object ThisSW, int Cookie)

Parameters

ThisSW object
Cookie int

Returns

bool

DisconnectFromSW()

SOLIDWORKS calls these command once addin is unloaded.

public bool DisconnectFromSW()

Returns

bool

GetUserInterFace()

Override this method to define your add-in's user interface including command tabs, command groups, and property manager pages.

public abstract AddinUserInterface GetUserInterFace()

Returns

AddinUserInterface

An AddinUserInterface instance containing all UI elements for your add-in.

Examples

Simple implementation:

public override AddinUserInterface GetUserInterFace()
{
    return new AddinUserInterface
    {
        CommandTabs = new List<AddinCommandTab>
        {
            new MyCommandTab()
        },
        PropertyManagerPages = new List<PropertyManagerPageX64>
        {
            new MyPropertyManagerPage(_solidworks)
        },
        IconsRootDir = new DirectoryInfo(
            Path.Combine(Environment.GetFolderPath(
                Environment.SpecialFolder.LocalApplicationData), "MyAddinIcons"))
    };
}

Remarks

This method is called by SolidWorks during add-in initialization. The returned AddinUserInterface should contain:

Important: Callback method names (e.g., EnableMethod, CallBackFunction) must reference public methods defined in your add-in class.

See Also

Register(Type)

registers Type provided to Register Helper so SolidWORKS can find it

public static void Register(Type t)

Parameters

t Type

type of class that inherits from AddinMaker

Unregister(Type)

unregisters the addin once removed or when the project is cleaned

public static void Unregister(Type t)

Parameters

t Type

Events

OnExit

Occurs when the add-in is being unloaded from SolidWorks.

public event EventHandler<OnConnectToSwEventArgs> OnExit

Event Type

EventHandler<OnConnectToSwEventArgs>

Examples

public MyAddin()
{
    OnExit += (sender, e) =>
    {
        // Save user settings
        Settings.Save();

        // Clean up resources
        _myResource?.Dispose();
    };
}

Remarks

This event fires when the user disables the add-in (unchecks it in Tools → Add-Ins) or when SolidWorks is closing. Use this event to clean up resources, save settings, and release any COM objects.

The event uses weak references to prevent memory leaks. Handlers are automatically cleared after the event fires.

OnStart

Occurs when the add-in successfully connects to SolidWorks.

public event EventHandler<OnConnectToSwEventArgs> OnStart

Event Type

EventHandler<OnConnectToSwEventArgs>

Examples

public class MyAddin : AddinMaker
{
    private ISldWorks _solidworks;

    public MyAddin()
    {
        OnStart += (sender, e) =>
        {
            _solidworks = e.Solidworks;
            // Initialize resources, load settings, etc.
        };
    }
}

Remarks

This is the recommended place to obtain the SolidWorks.Interop.sldworks.ISldWorks reference and perform any initialization that requires SolidWorks to be available.

The event uses weak references to prevent memory leaks. Handlers are automatically cleared after the event fires.

See Also