← LibrarySolidWorks API: Property Manager Pages and the Control ModelEngineering · ComputersLesson 5/10← PrevNext →
GuidePublished 4 Aug 20268 min readBy Kevin JoginSolidWorks APIuser interfaceProperty Manager Pageadd-in development

KEVOS® Knowledge Library · SolidWorks API Add-in Development

Property Manager Pages and the Control Model

The handler class, the page creation call, the control catalogue and the identifier-driven callback model behind the panel most add-ins use as their primary interface.

01Executive summary

A Property Manager Page is a panel hosted inside SolidWorks in the same position as the feature tree. It is the interface device most add-ins reach for, because it looks and behaves like the native modelling commands rather than like a bolted-on dialog.

The pattern is consistent: a handler class implements the page handler interface, creates the page in its constructor, adds controls in a dedicated method, and receives every user interaction through callback methods that identify the control by an integer you assigned. The discipline that makes this pleasant rather than painful is the identifier convention — one constant per control, one field per control handle, and no exceptions.

14control types available
1handler interface to implement
1integer identifier per control
2teardown obligations

02The handler class

Pages are driven by a class that implements the page handler interface. Implementing it generates a long list of members — these are the callbacks SolidWorks invokes as the user interacts with the page. Most will remain empty; the ones you fill are the page's behaviour.

  1. StructureImplement the handler interface

    Generate every member of the interface. Clear the auto-generated bodies, return a benign value from any member that returns one, and leave the rest empty until needed.

  2. StructureCreate the page in the constructor

    The constructor takes the application object and creates the page, so that constructing an instance and having a page are the same event.

  3. StructureAdd controls in a dedicated method

    Called immediately after successful creation. Keeping it separate makes the layout readable and lets you rebuild controls without recreating the page.

  4. StructureExpose an explicit show method

    Creation and display are separate concerns. A page can exist without being visible, which is what multi-page add-ins rely on.

  5. StructureRelease in the after-close callback

    Null the page handle and every control handle when the page closes, not when the add-in unloads.

03Creating the page

MethodISldWorks.CreatePropertyManagerPage
object CreatePropertyManagerPage(
    string Title,
    int    Options,
    object Handler,
    ref int Errors
)
Title
Heading shown at the top of the panel.
Options
Bit mask from the page options enumerator. Common members select the green confirmation button, a close button, and whether the page is locked so that it stays put during other operations.
Handler
The instance implementing the page handler interface that will receive the callbacks — normally the class making the call.
Errors
Passed by reference and populated with a value from the page status enumerator. It must be checked: creation can fail while still returning an object.
C# — creation with both failure paths handledIllustrative
public bool Ok { get; private set; }

private IPropertyManagerPage2 _page;
private ISldWorks _sw;
private int _errors;

public InfoPage(ISldWorks app)
{
    _sw = app;

    try
    {
        _page = (IPropertyManagerPage2)_sw.CreatePropertyManagerPage(
            "Model information",
            (int)(swPropertyManagerPageOptions_e
                    .swPropertyManagerOptions_OkayButton |
                  swPropertyManagerPageOptions_e
                    .swPropertyManagerOptions_LockedPage),
            this,
            ref _errors);

        // A returned object does not mean success.
        if (_errors != (int)swPropertyManagerPageStatus_e
                            .swPropertyManagerPage_Okay)
        {
            Report("Page could not be created: " +
                   ((swPropertyManagerPageStatus_e)_errors));
            Ok = false;
            return;
        }

        AddControls();
        Ok = true;
    }
    catch (Exception ex)
    {
        Report("Page could not be created: " + ex.Message);
        Ok = false;
    }
}
Two independent failure modes

The status value reports a page that the API declined to build. The exception path catches everything else. Handling only one of them leaves a class that reports success and then fails at the moment it is shown — inside the host process.

04The control catalogue

Controls are added to the page after it exists. Every control needs a caption, an alignment, an options mask and a tooltip; because most controls share the same alignment and options, those are normally computed once and reused.

MethodIPropertyManagerPage2.AddControl
object AddControl(
    short  ID,
    short  ControlType,
    string Caption,
    short  LeftAlign,
    int    Options,
    string Tip
)
ID
Your identifier for the control. It is the value handed back to you in every callback, so it is how you know which control the user touched.
ControlType
A member of the control type enumerator.
Caption
Label text for the control.
LeftAlign
A member of the left-alignment enumerator, controlling indentation against the page edge or the enclosing group.
Options
Bit mask combining at minimum the enabled and visible flags.
Tip
Hover text for the control.
Return value
A handle to the created control, typed to the control class. Store it — you will need it to read and write values later.
Control types available on a Property Manager Page
ControlTypical usePrimary callback
LabelStatic text and captionsNone
TextboxFree text entry and read-back of valuesText changed
NumberboxNumeric entry with units and rangeValue changed
CheckboxIndependent on/off settingCheck changed
OptionMutually exclusive choice within a groupOption checked
ComboboxSelection from a generated listSelection changed
ListboxSelection from a longer or multi-select listSelection changed
ButtonDiscrete actionButton pressed
Bitmap buttonAction represented by an iconButton pressed
Checkable bitmap buttonToggle represented by an iconCheck changed
SelectionboxCapturing geometry selected in the graphics areaSelection changed
SliderBounded continuous adjustmentPosition changed
BitmapStatic imageNone
ActiveX controlHosting an external controlControl created
C# — adding controls with a shared option setIllustrative
private const short IdFileName   = 1;
private const short IdRefresh    = 2;
private const short IdSheetList  = 3;

private IPropertyManagerPageLabel    _lblFileName;
private IPropertyManagerPageButton   _btnRefresh;
private IPropertyManagerPageCombobox _cboSheets;

private void AddControls()
{
    _page.SetMessage3(
        "Information about the active document.",
        (int)swPropertyManagerPageMessageVisibility
                .swImportantMessageBox,
        (int)swPropertyManagerPageMessageExpanded
                .swMessageBoxMaintainExpandState,
        "Model information");

    int opts = (int)(swAddControlOptions_e.swControlOptions_Enabled |
                     swAddControlOptions_e.swControlOptions_Visible);
    short align = (short)swPropertyManagerPageControlLeftAlign_e
                            .swControlAlign_LeftEdge;

    _lblFileName = (IPropertyManagerPageLabel)_page.AddControl(
        IdFileName,
        (short)swPropertyManagerPageControlType_e.swControlType_Label,
        "Document", align, opts, "Active document name");

    _btnRefresh = (IPropertyManagerPageButton)_page.AddControl(
        IdRefresh,
        (short)swPropertyManagerPageControlType_e.swControlType_Button,
        "Refresh", align, opts, "Re-read the active document");
}
The built-in message area

Every page carries a hidden group and label at the top. Setting its message and visibility reveals it, which gives you a conventional place to explain what the page does or to report state without adding a control of your own.

05The identifier-driven callback model

Interaction does not arrive as a delegate attached to a control. It arrives as a call to a handler member, carrying the identifier you assigned. One method therefore serves every button on the page, and dispatch is your responsibility.

C# — dispatching by identifierIllustrative
public void OnButtonPress(int Id)
{
    switch (Id)
    {
        case IdRefresh:
            RefreshFromActiveDocument();
            break;
    }
}

public void OnComboboxSelectionChanged(int Id, int Item)
{
    switch (Id)
    {
        case IdSheetList:
            ActivateSheet(Item);
            break;
    }
}

public void AfterClose()
{
    // Release page and control handles here, not at unload.
    _cboSheets = null;
    _btnRefresh = null;
    _lblFileName = null;
    _page = null;
}
Identifier discipline

Number identifiers from one, declare them as constants next to the field holding the control handle, and never reuse a value. When a page grows past a dozen controls this convention is the only thing standing between you and a switch statement full of magic numbers.

06Showing, hiding and multi-page behaviour

Creation and display are deliberately separate. An add-in that presents a different layout for parts, assemblies and drawings creates the controls for all three, then shows and hides groups as the active document changes — which is far cheaper than tearing down and rebuilding the page on every switch.

  1. Create once

    Build the page and every control group at construction, including the groups that are not initially relevant.

  2. Toggle visibility

    On a document change, hide the groups that do not apply and show the one that does, then repopulate its values.

  3. Show with the right mode

    The display call takes a mode argument. The stacked mode is what keeps a page open across the events that would otherwise dismiss it — essential for a page intended to persist while the user works.

  4. Release on close

    Handle the after-close callback and null every handle. The page may be closed by the user at any time, independently of the add-in's lifetime.

Verify persistence on real machines

Page display modes interact with the host's own event handling, and behaviour has historically varied between installations. A page that stays open reliably on the development machine is not evidence that it will do so everywhere. Test persistence across a spread of workstations before relying on it.

07Quick reference

Handler
One class implementing the page handler interface; every member generated, most left empty.
Creation
Title, options mask, handler, and an error value passed by reference — check it.
Controls
Added after creation; each returns a typed handle you must store.
Identity
One constant identifier per control, matched to the field holding its handle.
Interaction
Callbacks carry the identifier; dispatch is yours to write.
Message area
Built into every page; reveal it rather than adding a label of your own.
Teardown
Null the page and all control handles in the after-close callback.

08Where this leads

Continue in this pathway

Continue learning

SolidWorks API: Command Manager, Menus and ToolbarsGuide · ComputersNEXT LESSON →SolidWorks API: Event and Notification ArchitectureGuide · ComputersSolidWorks API: COM Registration and Add-in DiscoveryGuide · ComputersSolidWorks API: Add-in, Stand-alone or HybridGuide · Computers