SwEx framework allows defining the commands in the enumerator. In this case the enumerator value become the id of the command.

Commands can be decorated with the additional attributes to define look and feel of the command.

Title

User friendly title can be defined using the TitleAttribute. Alternatively, any attribute class which inherits DisplayNameAttribute is supported as a title.

Description

Description is a text displayed in the SOLIDWORKS command bar when user hovers the mouse over the command. Description can be defined using the DescriptionAttribute

Icon

Icon can be set using the CommandIconAttribute. There are multiple overloads of this attribute. User can provide

  • Single master icon
  • 2 icons (small and large)
  • 6 icons for high resolution (supported from SOLIDWORKS 2016 onwards)

Icon can be also specified using the generic IconAttribute.

Regardless of the option selected above SwEx framework will scale the icon appropriately to match the version of SOLIDWORKS. For example if single master icon specified for SOLIDWORKS 2016 onwards, 6 icons will be created to support high resolution, for older SOLIDWORKS, 2 icons will be created (large and small). If user specified 6 icons - all of them will be used ‘as is’ for SOLIDWORKS 2016 or newer, but they will be converted to 2 (small and large) icons for older versions as high resolutions icons are not supported in SOLIDWORKS older than 2016.

Transparency is supported. SwEx framework will automatically assign the required transparency key for compatibility with SOLIDWORKS.

Icons can be referenced from any static class. Usually this should be a resource class. It is required to specify the type of the resource class as first parameter, and the resource names as additional parameters. Use nameof keyword to load the resource name to avoid usage of ‘magic’ strings.

Additional command item info

CommandItemInfoAttribute allows providing more information about the item command (applied to enumerator values):

  • Visibility in menu or toolbar
  • Default supported workspaces (e.g. Part, Assembly or both). SwEx framework will handle the command enable state based on these settings.

Additional command group info

CommandGroupInfoAttribute allows to assign the static command id to the group. This should be applied to the enumerator definition. If this attribute is not used SwEx framework will assign the ids automatically.

Example

C#

using CodeStack.SwEx.AddIn.Attributes;
using CodeStack.SwEx.AddIn.Enums;
using CodeStack.SwEx.AddIn.Examples.SwExportComponent.Properties;
using SolidWorks.Interop.swconst;
using System.ComponentModel;

namespace CodeStack.SwEx.AddIn.Examples.SwExportComponent
{
    [Title(typeof(Resources), nameof(Resources.ToolbarTitle))]
    [Description("Exports selected component to neutral format")]
    [Icon(typeof(Resources), nameof(Resources.export))]
    public enum ExportCommands_e
    {
        [Title("Export To Parasolid")]
        [Description("Exports selected component to parasolid")]
        [Icon(typeof(Resources), nameof(Resources.export_parasolid))]
        [CommandItemInfo(true, true, swWorkspaceTypes_e.Assembly,
            true, swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow)]
        Parasolid,

        [Title("Export To Iges")]
        [Description("Exports selected component to iges")]
        [Icon(typeof(Resources), nameof(Resources.export_iges))]
        [CommandItemInfo(true, true, swWorkspaceTypes_e.Assembly,
            true, swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow)]
        Iges,

        [Title("Export To Step")]
        [Description("Exports selected component to step")]
        [Icon(typeof(Resources), nameof(Resources.export_step))]
        [CommandItemInfo(true, true, swWorkspaceTypes_e.Assembly,
            true, swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow)]
        Step
    }
}

VB.NET

Imports CodeStack.SwEx.AddIn.Attributes
Imports CodeStack.SwEx.AddIn.Enums
Imports CodeStack.SwEx.AddIn.Examples.SwExportComponent.My.Resources
Imports System.ComponentModel
Imports SolidWorks.Interop.swconst

<Title(GetType(Resources), NameOf(Resources.ToolbarTitle))>
<Description("Exports selected component to neutral format")>
<Icon(GetType(Resources), NameOf(Resources.export))>
Public Enum ExportCommands_e

	<Title("Export To Parasolid")>
	<Description("Exports selected component to parasolid")>
	<Icon(GetType(Resources), NameOf(Resources.export_parasolid))>
	<CommandItemInfo(True, True, swWorkspaceTypes_e.Assembly,
					 True, swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow)>
	Parasolid

	<Title("Export To Iges")>
	<Description("Exports selected component to iges")>
	<Icon(GetType(Resources), NameOf(Resources.export_iges))>
	<CommandItemInfo(True, True, swWorkspaceTypes_e.Assembly,
					 True, swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow)>
	Iges

	<Title("Export To Step")>
	<Description("Exports selected component to step")>
	<Icon(GetType(Resources), NameOf(Resources.export_step))>
	<CommandItemInfo(True, True, swWorkspaceTypes_e.Assembly,
					 True, swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow)>
	[Step]

End Enum