Skip to content

xCAD provides utilities for simplified development of SOLIDWORKS add-ins. These types of applications running in-process and enables best user experience.

The functionality includes

  • Automatic registration of the add-in
  • Simplified commands groups management
  • Events management
  • Task Panes, Feature Manager Tab, Model View Tab

Features Overview

Although some of the feature below, such as documents and events management, reading or writing to the 3rd party streams can be used from Stand-Alone applications, in most cases this functionality is used within add-ins.

Registering Add-In

To Register add-in just declare a public class and add COMVisible attribute (no need to run custom regasm commands, no need to call any static classes).

cs
[ComVisible(true), Guid("736EEACF-B294-40F6-8541-CFC8E7C5AA61")]
public class SampleAddIn : SwAddInEx
{

Adding Commands

Commands can be defined by creating an enumerations. Commands can be customized by adding attributes to assign title, tooltip, icon etc. Commands can be grouped under sub menus. Simply specify the image (transparency is supported) and framework will create required bitmaps compatible with SOLIDWORKS. No need to assign gray background to enable transparency, no need to scale images to fit the required sizes - simply use any image and framework will do the rest. Use resources to localize the add-in.

cs
[Title(typeof(Resources), nameof(Resources.ToolbarTitle)), Description("Toolbar with commands")]
[Icon(typeof(Resources), nameof(Resources.commands))]
public enum Commands_e
{
    [Title("Command 1"), Description("Sample command 1")]
    [Icon(typeof(Resources), nameof(Resources.command1))]
    [CommandItemInfo(true, true, WorkspaceTypes_e.Assembly, true, RibbonTabTextDisplay_e.TextBelow)]
    Command1,
    Command2
}
cs
this.CommandManager.AddCommandGroup<Commands_e>().CommandClick += OnButtonClick;
cs
private void OnButtonClick(Commands_e cmd)
{
    //handle commands
}

Managing Documents Lifecycle and Events

Framework will manage the lifecycle of documents by wrapping them in the specified class and allows to handle common events:

cs
public class MyDocumentHandler : SwDocumentHandler
{
    protected override void AttachAssemblyEvents(AssemblyDoc assm)
    {
        assm.FileSaveNotify += OnFileSave;
        assm.RegenNotify += OnRegen;
    }

    protected override void AttachPartEvents(PartDoc part)
    {
        part.FileSaveNotify += OnFileSave;
        part.RegenNotify += OnRegen;
    }

    protected override void AttachDrawingEvents(DrawingDoc draw)
    {
        draw.FileSaveNotify += OnFileSave;
        draw.RegenNotify += OnRegen;
    }

    private int OnFileSave(string FileName)
    {
        //handle saving
        return S_OK;
    }

    private int OnRegen()
    {
        //handle rebuild
        return S_OK;
    }

    protected override void DetachAssemblyEvents(AssemblyDoc assm)
    {
        assm.FileSaveNotify -= OnFileSave;
        assm.RegenNotify -= OnRegen;
    }

    protected override void DetachPartEvents(PartDoc part)
    {
        part.FileSaveNotify -= OnFileSave;
        part.RegenNotify -= OnRegen;
    }

    protected override void DetachDrawingEvents(DrawingDoc draw)
    {
        draw.FileSaveNotify -= OnFileSave;
        draw.RegenNotify -= OnRegen;
    }
}

Reading and Writing to 3rd Party Storage and Store

It has never been easier to read and write data to the internal SOLIDWORKS file storage. Simply override the corresponding event and serialize/deserialize the data using XML, DataContract, Binary etc. serializers:

cs
Application.Documents.Active.StreamWriteAvailable += OnWriteToStream;

Hosting User Controls In SOLIDWORKS Panels

Just specify User Control to host and framework will do the rest:

Task Pane

cs
public class TaskPaneControl : UserControl
{
}
cs
public enum TaskPaneCommands_e
{
    Command1
}
cs
var taskPane = this.CreateTaskPane<TaskPaneControl, TaskPaneCommands_e>();
taskPane.ButtonClick += OnTaskPaneCommandClick;
TaskPaneControl ctrl = taskPane.Control;
cs
private void OnTaskPaneCommandClick(TaskPaneCommands_e cmd)
{
    switch (cmd)
    {
        case TaskPaneCommands_e.Command1:
            //handle command
            break;
    }
}