CodeStack.SwEx.AddIn 0.7.0

Suggested Alternatives

Xarial.XCad.SolidWorks

There is a newer version of this package available.
See the version list below for details.
dotnet add package CodeStack.SwEx.AddIn --version 0.7.0
NuGet\Install-Package CodeStack.SwEx.AddIn -Version 0.7.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CodeStack.SwEx.AddIn" Version="0.7.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CodeStack.SwEx.AddIn --version 0.7.0
#r "nuget: CodeStack.SwEx.AddIn, 0.7.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CodeStack.SwEx.AddIn as a Cake Addin
#addin nuget:?package=CodeStack.SwEx.AddIn&version=0.7.0

// Install CodeStack.SwEx.AddIn as a Cake Tool
#tool nuget:?package=CodeStack.SwEx.AddIn&version=0.7.0

Change Log Documentation NuGet Issues

When updating nuget package 0.7.0 or newer check the Changelog for the list of members which were remove and their replacements.

SwEx.AddIn

SwEx.AddIn SwEx.AddIn enables SOLIDWORKS add-in developers to develop robust applications using SOLIDWORKS API significantly simplifying the add-in creation process

Getting started

  • Create public com-visible class which inherits SwAddInEx class
  • Add-in registration process can be simplified by adding the AutoRegister attribute to add-in class. Check Register for COM Interop option in the project settings
[AutoRegister("My C# SOLIDWORKS Add-In", "Sample SOLIDWORKS add-in in C#", true)]
[ComVisible(true)]
public class SwExportComponentAddIn : SwAddInEx
{
}
<AutoRegister("My VB.NET SOLIDWORKS Add-In", "Sample SOLIDWORKS add-in in VB.NET", True)>
<ComVisible(True)>
Public Class SwExportComponentAddIn
    Inherits SwAddInEx
End Class
  • Overload OnConnect method to initiate the add-in. Access the pointer to the SLDWORKS application via m_App field.

Adding commands

Command manager

Framework allows to create commands and their handlers by simply defining them in the enumeration and providing the handler function via AddCommandGroup method.

Commands can be decorated with the attributes to provide their title and icon. Framework will automatically generate the icons in correct sizes and formats.

public enum Commands_e
{
    CreateCylinder
}
...
this.AddCommandGroup<Commands_e>(OnButtonClick);
...
private void OnButtonClick(Commands_e cmd)
{
    switch (cmd)
    {
        case Commands_e.CreateCylinder:
            //TODO: do something
            break;
    }
}

Managing Documents

Utility allows to handle documents lifecycle by providing the document handler type.

private IDocumentsHandler<MyDocHandler> m_DocHandler;
...
m_DocHandler = CreateDocumentsHandler<MyDocHandler>();
...
public class MyDocHandler : DocumentHandler
{
    public override void OnInit()
    {
        //TODO: init
    }

    public override void OnDestroy()
    {
        //TODO: release
    }
}

Accessing 3rd Party Storage Store And Stream

Utility to read and write data to 3rd party storage store and stream

public override void OnSaveToStream()
{
    using (var streamHandler = Model.Access3rdPartyStream(STREAM_NAME, true))
    {
        using (var str = streamHandler.Stream)
        {
            var xmlSer = new XmlSerializer(typeof(RevData));

            xmlSer.Serialize(str, m_RevData);
        }
    }
}

public override void OnLoadFromStream()
{
    using (var streamHandler = Model.Access3rdPartyStream(STREAM_NAME, false))
    {
        if (streamHandler.Stream != null)
        {
            using (var str = streamHandler.Stream)
            {
                var xmlSer = new XmlSerializer(typeof(RevData));
                var data = xmlSer.Deserialize(str) as RevData;
            }
        }
    }
}

public override void OnLoadFromStorageStore()
{
    using (var storageHandler = Model.Access3rdPartyStorageStore(STORAGE_NAME, false))
    {
        if (storageHandler.Storage != null)
        {
            using (var str = storageHandler.Storage.TryOpenStream(STREAM_NAME, false))
            {
                var xmlSer = new XmlSerializer(typeof(RevData));
                var data = xmlSer.Deserialize(str) as RevData;
            }
        }
    }
}

public override void OnSaveToStorageStore()
{
    using (var storageHandler = Model.Access3rdPartyStorageStore(STORAGE_NAME, true))
    {
        using (var subStorage = storageHandler.Storage.TryOpenStorage(SUB_STORAGE_NAME, true))
        {
            using (var str = subStorage.TryOpenStreamSTREAM_NAME, true))
            {
                var buffer = Encoding.UTF8.GetBytes(DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss"));
                str.Write(buffer, 0, buffer.Length);
            }
        }
    }
}

Creating Hosted Controls

Task Pane

Create task pane and host User Control

public enum TaskPaneCommands_e
{
    Command1
}

...
TaskPaneControl ctrl;
var taskPaneView = CreateTaskPane<TaskPaneControl, TaskPaneCommands_e>(OnTaskPaneCommandClick, out ctrl);
...

private void OnTaskPaneCommandClick(TaskPaneCommands_e cmd)
{
    switch (cmd)
    {
        case TaskPaneCommands_e.Command1:
            //TODO: handle command
            break;
    }
}
Product Compatible and additional computed target framework versions.
.NET Framework net40 is compatible.  net403 was computed.  net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.8.1 2,185 10/4/2019
0.8.0 796 10/2/2019
0.7.6 815 8/25/2019
0.7.5 736 7/18/2019
0.7.0 788 5/21/2019
0.4.1 822 1/6/2019
0.4.0 787 12/30/2018
0.3.1 822 11/16/2018
0.3.0 865 11/4/2018
0.2.2-beta 730 8/25/2018