Hide Table of Contents

Create PropertyManager Page Example (VB.NET)

This example shows how to create a PropertyManager page that contains two selection boxes, a combo box,

and a list box. This example also shows how to handle focus events for these controls.


NOTE: If the model is an assembly and it contains multiple components and you want to allow the user to

select edges, faces, or vertices, then you must specify swSelCOMPSDONTOVERRIDE as an element of

SelType for the ISldWorks::SetSelectionFilters method. Otherwise, if the user attempts to select an

edge, face, or vertex, then the entire component might get selected and not the edge, face, or vertex.

This example demonstrates how to specify the elements for SelType.



' Preconditions:

' 1. Copy Modules - main to your project.

' 2. Copy Class Modules - clsPropMgr to a class in your project.

' 3. Add the SolidWorks.Interop.swpublished primary interop assembly

'    reference to your project (right-click the name of your project, select

'    Add Reference, and select SolidWorks.Interop.swpublished on the .NET

'    tab.

' 4. Ensure that the assembly document opened by the macro exists.

' 5. Run the macro to open the assembly document and PropertyManager page.


' Postconditions:

' A PropertyManager page called Comps is created. Comps contains a selection box

' where the user's selections are shown, a drop-down combo box where Value 2

' is selected, and a list box where Value 1 is selected.


' Examine the contents of Comps and the Immediate Window as you

' perform each of these steps:

' 1. Click a component in the assembly to add to the

'    first selection box.

' 2. Locate, but do not move, the cursor in the graphics area.

' 3. Press the right-mouse button.

' 4. Click a component in the assembly to add to the second selection box.

' 5. Click Value 4 in the list box at the bottom of Comps.

' 6. Click Value 1 in the list box at the bottom of Comps.

' 7. Click the first selection box.

' 8. Close the PropertyManager page.



'  *  After running this macro, select the

'     Tools > Options > System Options > Stop VSTA debugger

'     on macro exit checkbox.

'  *  Because the assembly document is used elsewhere,

'     do not save any changes when closing the document.


'Modules - main

Imports SolidWorks.Interop.sldworks

Imports SolidWorks.Interop.swconst

Imports System


Partial Class SolidWorksMacro


    Public Part As ModelDoc2

    Public WithEvents pm As clsPropMgr


    Sub main()


        Dim openDocErrors As Long

        Dim OpenDocWarnings As Long


        swApp.SetUserPreferenceToggle(swUserPreferenceToggle_e.swStopDebuggingVstaOnExit, False)


        Part = swApp.OpenDoc6("c:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\advdrawings\bladed shaft.sldasm", swDocumentTypes_e.swDocASSEMBLY, swOpenDocOptions_e.swOpenDocOptions_Silent, "", openDocErrors, OpenDocWarnings)


        'Create a new instance of the PropertyManager class

        pm = New clsPropMgr(swApp)



    End Sub      


    Public swApp As SldWorks


End Class


Back to top

'Class Modules - clsPropMgr

Imports SolidWorks.Interop.sldworks

Imports SolidWorks.Interop.swconst

Imports SolidWorks.Interop.swpublished

Imports System

Imports System.Runtime.InteropServices

Imports System.Diagnostics


<ComVisibleAttribute(True)> _

Public Class clsPropMgr


    Implements PropertyManagerPage2Handler9


    Dim swApp As SldWorks


    'General objects required for the PropertyManager page

    Dim pm_Page As PropertyManagerPage2

    Dim pm_Group As PropertyManagerPageGroup

    Dim pm_Selection As PropertyManagerPageSelectionbox

    Dim pm_Selection2 As PropertyManagerPageSelectionbox

    Dim pm_Label As PropertyManagerPageLabel

    Dim pm_Combo As PropertyManagerPageCombobox

    Dim pm_List As PropertyManagerPageListbox


    'Each object in the page needs a unique ID

    Const GroupID As Integer = 1

    Const LabelID As Integer = 2

    Const SelectionID As Integer = 3

    Const ComboID As Integer = 4

    Const ListID As Integer = 5

    Const Selection2ID As Integer = 6


    Dim ClickedCancel As Boolean

    Dim retVal As Integer


    Sub Show()


    End Sub


    'The following runs when a new instance

    'of the class is created

    Public Sub New(ByVal swApp As SldWorks)


        Dim PageTitle As String

        Dim caption As String

        Dim tip As String

        Dim options As Long

        Dim longerrors As Long

        Dim controlType As Integer

        Dim alignment As Integer

        Dim listItems(3) As String


        'Set the variables for the page

        PageTitle = "Comps"

        options = swPropertyManagerButtonTypes_e.swPropertyManager_OkayButton _

            + swPropertyManagerButtonTypes_e.swPropertyManager_CancelButton _

            + swPropertyManagerPageOptions_e.swPropertyManagerOptions_LockedPage _

            + swPropertyManagerPageOptions_e.swPropertyManagerOptions_PushpinButton


        'Create the PropertyManager page

        pm_Page = CType(swApp.CreatePropertyManagerPage(PageTitle, _

            options, Me, longerrors), PropertyManagerPage2)


        'Make sure that the page was created properly

        If longerrors = swPropertyManagerPageStatus_e.swPropertyManagerPage_Okay Then

            'Begin adding the controls to the page


            'Create the group box

            caption = "Comps"

            options = swAddGroupBoxOptions_e.swGroupBoxOptions_Visible + _


            pm_Group = pm_Page.AddGroupBox(GroupID, caption, options)


            'Create two selection boxes

            controlType = swPropertyManagerPageControlType_e.swControlType_Selectionbox

            caption = ""  ' No caption for selection boxes

            alignment = swPropertyManagerPageControlLeftAlign_e.swControlAlign_Indent

            options = swAddControlOptions_e.swControlOptions_Visible + _


            tip = "Select an edge, face, vertex, solid body, or a component"

            pm_Selection = pm_Group.AddControl(SelectionID, _

                controlType, caption, alignment, options, tip)

            pm_Selection2 = pm_Group.AddControl(Selection2ID, _

                controlType, caption, alignment, options, tip)

            Dim filters(6) As swSelectType_e

            filters(0) = swSelectType_e.swSelEDGES

            filters(1) = swSelectType_e.swSelREFEDGES

            filters(2) = swSelectType_e.swSelFACES

            filters(3) = swSelectType_e.swSelVERTICES

            filters(4) = swSelectType_e.swSelSOLIDBODIES

            filters(5) = swSelectType_e.swSelCOMPONENTS

            filters(6) = swSelectType_e.swSelCOMPSDONTOVERRIDE

            Dim filterObj As Object

            filterObj = filters

            pm_Selection.SingleEntityOnly = False

            pm_Selection.AllowMultipleSelectOfSameEntity = True

            pm_Selection.Height = 50


            pm_Selection2.SingleEntityOnly = False

            pm_Selection2.AllowMultipleSelectOfSameEntity = True

            pm_Selection2.Height = 50



            ' Create a combo box

            controlType = swPropertyManagerPageControlType_e.swControlType_Combobox

            caption = ""

            alignment = swPropertyManagerPageControlLeftAlign_e.swControlAlign_Indent

            options = swAddControlOptions_e.swControlOptions_Visible + _



            tip = "Select a value from the drop-down"

            pm_Combo = pm_Group.AddControl(ComboID, _

                controlType, caption, alignment, options, tip)

            If Not pm_Combo Is Nothing Then

                pm_Combo.Height = 50

                listItems(0) = "Value 1"

                listItems(1) = "Value 2"

                listItems(2) = "Value 3"

                listItems(3) = "Value 4"


                pm_Combo.CurrentSelection = 0

            End If


            ' Create a list box

            controlType = swPropertyManagerPageControlType_e.swControlType_Listbox

            caption = ""

            alignment = swPropertyManagerPageControlLeftAlign_e.swControlAlign_Indent

            options = swAddControlOptions_e.swControlOptions_Visible + _


            tip = "Multi-select values from the list box"

            pm_List = pm_Group.AddControl(ListID, _

                controlType, caption, alignment, options, tip)

            pm_List.Style = swPropMgrPageListBoxStyle_e.swPropMgrPageListBoxStyle_MultipleItemSelect

            pm_List.Height = 50

            If Not pm_List Is Nothing Then

                pm_List.Height = 50

                listItems(0) = "Value 1"

                listItems(1) = "Value 2"

                listItems(2) = "Value 3"

                listItems(3) = "Value 4"


                pm_List.SetSelectedItem(1, True)

            End If


        Else  'If the page is not created


            MsgBox("An error occurred while attempting to create the " _

                & "PropertyManager Page", vbCritical)


        End If


    End Sub


    Public Sub AfterActivation() Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.AfterActivation

    End Sub


    Public Sub AfterClose() Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.AfterClose

    End Sub


    Public Function OnActiveXControlCreated(ByVal Id As Integer, ByVal Status As Boolean) As Integer Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnActiveXControlCreated

    End Function


    Public Sub OnButtonPress(ByVal Id As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnButtonPress

    End Sub


    Public Sub OnCheckboxCheck(ByVal Id As Integer, ByVal Checked As Boolean) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnCheckboxCheck

    End Sub


    Public Sub OnClose(ByVal Reason As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnClose

        If Reason = swPropertyManagerPageCloseReasons_e.swPropertyManagerPageClose_Cancel Then

            'Cancel button was clicked

            ClickedCancel = True

        ElseIf Reason = swPropertyManagerPageCloseReasons_e.swPropertyManagerPageClose_Okay Then

            'OK button was clicked

            ClickedCancel = False

        End If

    End Sub


    Public Sub OnComboboxEditChanged(ByVal Id As Integer, ByVal Text As String) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnComboboxEditChanged

    End Sub


    Public Sub OnComboboxSelectionChanged(ByVal Id As Integer, ByVal Item As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnComboboxSelectionChanged

    End Sub


    Public Sub OnGainedFocus(ByVal Id As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnGainedFocus

        Dim varArray As Object

        Debug.Print("Control box " & Id & " has gained focus")

        varArray = pm_List.GetSelectedItems

        pm_Combo.CurrentSelection = varArray(0)

    End Sub


    Public Sub OnGroupCheck(ByVal Id As Integer, ByVal Checked As Boolean) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnGroupCheck

    End Sub


    Public Sub OnGroupExpand(ByVal Id As Integer, ByVal Expanded As Boolean) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnGroupExpand

    End Sub


    Public Function OnHelp() As Boolean Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnHelp

    End Function


    Public Function OnKeystroke(ByVal Wparam As Integer, ByVal Message As Integer, ByVal Lparam As Integer, ByVal Id As Integer) As Boolean Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnKeystroke

    End Function


    Public Sub OnListboxSelectionChanged(ByVal Id As Integer, ByVal Item As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnListboxSelectionChanged

    End Sub


    Public Sub OnLostFocus(ByVal Id As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnLostFocus

        Debug.Print("Control box " & Id & " has lost focus")

    End Sub


    Public Function OnNextPage() As Boolean Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnNextPage

    End Function


    Public Sub OnNumberboxChanged(ByVal Id As Integer, ByVal Value As Double) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnNumberboxChanged

    End Sub


    Public Sub OnOptionCheck(ByVal Id As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnOptionCheck

    End Sub


    Public Sub OnPopupMenuItem(ByVal Id As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnPopupMenuItem

    End Sub


    Public Sub OnPopupMenuItemUpdate(ByVal Id As Integer, ByRef retval As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnPopupMenuItemUpdate

    End Sub


    Public Function OnPreview() As Boolean Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnPreview

    End Function


    Public Function OnPreviousPage() As Boolean Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnPreviousPage

    End Function


    Public Sub OnRedo() Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnRedo

    End Sub


    Public Sub OnSelectionboxCalloutCreated(ByVal Id As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnSelectionboxCalloutCreated

    End Sub


    Public Sub OnSelectionboxCalloutDestroyed(ByVal Id As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnSelectionboxCalloutDestroyed

    End Sub


    Public Sub OnSelectionboxFocusChanged(ByVal Id As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnSelectionboxFocusChanged

        Debug.Print("The focus has moved to selection box " & Id)

    End Sub


    Public Sub OnSelectionboxListChanged(ByVal Id As Integer, ByVal Count As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnSelectionboxListChanged

        ' Move focus to next selection box if right-mouse button pressed


        Debug.Print("The list in selection box " & Id & " has changed")

    End Sub


    Public Sub OnSliderPositionChanged(ByVal Id As Integer, ByVal Value As Double) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnSliderPositionChanged

    End Sub


    Public Sub OnSliderTrackingCompleted(ByVal Id As Integer, ByVal Value As Double) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnSliderTrackingCompleted

    End Sub


    Public Function OnSubmitSelection(ByVal Id As Integer, ByVal Selection As Object, ByVal SelType As Integer, ByRef ItemText As String) As Boolean Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnSubmitSelection

        OnSubmitSelection = True

    End Function


    Public Function OnTabClicked(ByVal Id As Integer) As Boolean Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnTabClicked

    End Function


    Public Sub OnTextboxChanged(ByVal Id As Integer, ByVal Text As String) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnTextboxChanged

    End Sub


    Public Sub OnUndo() Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnUndo

    End Sub


    Public Sub OnWhatsNew() Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnWhatsNew

    End Sub


    Public Sub OnListBoxRMBUp(ByVal Id As Integer, ByVal posX As Integer, ByVal posY As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnListboxRMBUp

    End Sub

    Public Function OnWindowFromHandleControlCreated(ByVal Id As Integer, ByVal Status As Boolean) As Integer Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnWindowFromHandleControlCreated

    End Function


    Public Sub OnNumberBoxTrackingCompleted(ByVal Id As Integer, ByVal Value As Double) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnNumberBoxTrackingCompleted

    End Sub

End Class

Back to top

Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

Subject:   Feedback on Help Topics
Page:   Create PropertyManager Page Example (VB.NET)
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:


We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again

Web Help Content Version: API Help (English only) 2012 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.