Table of Contents

Class AddinModelBuilder

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

Fluent builder for creating SolidWorks add-in user interfaces.

public class AddinModelBuilder : AddinUserInterface, IAddinModelBuilder
Inheritance
AddinModelBuilder
Implements
Inherited Members

Examples

Complete example of building an add-in UI:

public override AddinUserInterface GetUserInterFace()
{
    var iconsPath = Path.Combine(
        Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
        "MyAddinIcons");

    return this.GetBuilder()
        .AddCommandTab()
            .WithTitle("My Tools")
            .That()
            .IsVisibleIn(new[] { swDocumentTypes_e.swDocPART, swDocumentTypes_e.swDocASSEMBLY })
            .SetCommandGroup(1)
                .WithTitle("Tools", AddinConstants.SolidworksMenu.Tools)
                .WithIcon(Properties.Resources.ToolsIcon)
                .Has()
                .Commands(() => new AddinCommand[]
                {
                    new AddinCommand("Run Tool", "Runs the tool", "Run Tool",
                        Properties.Resources.RunIcon,
                        nameof(RunToolCallback), nameof(CanRunTool))
                })
            .SaveCommandGroup()
        .SaveCommandTab()
        .AddPropertyManagerPage("Tool Settings", SolidWorks)
            .AddGroup("Options")
                .That()
                .HasTheseControls(new List<IPmpControl>
                {
                    new PmpTextBox("Default value"),
                    new PmpCheckBox() { Checked = true }
                })
            .SaveGroup()
        .SavePropertyManagerPage(out PropertyManagerPageX64 pmpFactory)
        .WithIconsPath(new DirectoryInfo(iconsPath))
        .Build();
}

Remarks

This class provides a fluent API for building add-in UIs with a chainable, readable syntax. Start by calling GetBuilder(AddinMaker) from your add-in class.

The builder supports creating:

  • Command tabs with command groups and buttons
  • Property manager pages with tabs, groups, and controls

Methods

AddCommandTab()

Adds a new command tab to the add-in's user interface.

public IFluentCommandTab AddCommandTab()

Returns

IFluentCommandTab

An IFluentCommandTab for fluent configuration of the command tab.

Examples

builder.AddCommandTab()
    .WithTitle("My Tab")
    .That()
    .IsVisibleIn(new[] { swDocumentTypes_e.swDocPART })
    .SetCommandGroup(1)
        // ... configure command group
    .SaveCommandGroup()
.SaveCommandTab();

Remarks

Command tabs appear in the SolidWorks ribbon. Each tab can contain multiple command groups, and each group contains command buttons.

Call SaveCommandTab() when finished configuring the tab.

AddPropertyManagerPage(string, ISldWorks)

Adds a property manager page to the add-in.

public IPmpUiModelFluent AddPropertyManagerPage(string title, ISldWorks solidworks)

Parameters

title string

The title displayed at the top of the property manager page.

solidworks ISldWorks

The SolidWorks application instance.

Returns

IPmpUiModelFluent

An IPmpUiModelFluent for fluent configuration of the page.

Examples

builder.AddPropertyManagerPage("My Settings", SolidWorks)
    .AddGroup("Options")
        .That()
        .HasTheseControls(new List<IPmpControl>
        {
            new PmpTextBox("Enter value"),
            new PmpButton("Apply", "Apply changes")
        })
        .SetExpansion(true)
    .SaveGroup()
    .OnClosing((pmp, reason) => { /* handle closing */ })
    .OnAfterClose((pmp, reason) => { /* handle after close */ })
.SavePropertyManagerPage(out PropertyManagerPageX64 pmpFactory);

Remarks

Property manager pages appear in the left panel of SolidWorks. They can contain tabs, groups, and various controls like text boxes, selection boxes, and buttons.

Call SavePropertyManagerPage(out PropertyManagerPageX64) when finished configuring.

Build()

Builds and returns the configured AddinUserInterface.

public AddinUserInterface Build()

Returns

AddinUserInterface

The fully configured AddinUserInterface instance.

Examples

return builder
    .AddCommandTab()
        // ... configure
    .SaveCommandTab()
    .WithIconsPath(new DirectoryInfo(iconsPath))
    .Build();  // Returns AddinUserInterface

Remarks

This method should be the last call in your fluent chain. It validates the configuration and returns the final AddinUserInterface that will be used by SolidWorks.

Exceptions

DirectoryNotFoundException

Thrown when WithIconsPath(DirectoryInfo) has not been called or was called with a null value.

CreatePropertyManagerPageTab(string, Bitmap)

Creates a standalone property manager page tab.

public IPmpTabFluent CreatePropertyManagerPageTab(string caption, Bitmap icon = null)

Parameters

caption string

The caption text displayed on the tab.

icon Bitmap

Optional icon displayed next to the caption.

Returns

IPmpTabFluent

An IPmpTabFluent for fluent configuration.

Remarks

Use this method when you need to create a tab separately from the main fluent chain. For most cases, use AddTab(string, Bitmap) instead.

WithIconsPath(DirectoryInfo)

Sets the directory where add-in icons will be stored.

public AddinModelBuilder WithIconsPath(DirectoryInfo iconsDir)

Parameters

iconsDir DirectoryInfo

The directory path. Should be a writable location like LocalApplicationData.

Returns

AddinModelBuilder

This builder instance for method chaining.

Examples

var iconsPath = Path.Combine(
    Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
    "MyAddinIcons");

builder.WithIconsPath(new DirectoryInfo(iconsPath));

Remarks

This method must be called before Build(). The directory will be created if it doesn't exist.

See Also