Hide Table of Contents

Create PropertyManager Page Example (VBA)

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 module in your project.

'    3. Add swpublished.tlb to your project (click Tools > References >

'       SolidWorks version exposed type libraries for add-in use).

'

' 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.

'

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

'      do the following:

'        1. Click a component in the assembly to add to the first selection box.

'        2. Observe, but do not move, the cursor.

'        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 on the first selection box.

'

' NOTE: Because the assembly document is used by a

'       SolidWorks online tutorial, do not save

'       any changes when closing the document.

'---------------------------------------

Modules - materials

Option Explicit

 

Public swApp As SldWorks.SldWorks

Public Part As SldWorks.ModelDoc2

Public pm As clsPropMgr

 

Sub main()

 

Dim openDocErrors As Long

Dim OpenDocWarnings As Long

 

Set swApp = Application.SldWorks

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

 

'Create a new instance of the PropertyManager class

Set pm = New clsPropMgr

pm.Show

 

End Sub

 

Class Modules - clsPropMgr

Option Explicit

 

'Required for PropertyManager page controls

Implements PropertyManagerPage2Handler7

 

'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()

    pm_Page.Show2 0    

End Sub

 

'The following runs when a new instance

'of the class is created

 

Private Sub Class_Initialize()

 

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 = swPropertyManager_OkayButton _

    + swPropertyManager_CancelButton _

    + swPropertyManagerOptions_LockedPage _

    + swPropertyManagerOptions_PushpinButton

 

'Create the PropertyManager page

Set pm_Page = swApp.CreatePropertyManagerPage(PageTitle, _

    options, Me, longerrors)

 

'Make sure that the page was created properly

If longerrors = swPropertyManagerPage_Okay Then

 

    'Begin adding the controls to the page

    

    'Create the group box

    caption = "Comps"

    options = swGroupBoxOptions_Visible + _

        swGroupBoxOptions_Expanded

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

 

    'Create two selection boxes

      controlType = swControlType_Selectionbox

      caption = ""  ' No caption for selection boxes

      alignment = swControlAlign_Indent

      options = swControlOptions_Visible + _

          swControlOptions_Enabled

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

      Set pm_Selection = pm_Group.AddControl(SelectionID, _

          controlType, caption, alignment, options, tip)

          

      Set pm_Selection2 = pm_Group.AddControl(Selection2ID, _

          controlType, caption, alignment, options, tip)

      Dim filters(6) As Long

      filters(0) = swSelEDGES

      filters(1) = swSelREFEDGES

      filters(2) = swSelFACES

      filters(3) = swSelVERTICES

      filters(4) = swSelSOLIDBODIES

      filters(5) = swSelCOMPONENTS

      filters(6) = swSelCOMPSDONTOVERRIDE

      pm_Selection.SingleEntityOnly = False

      pm_Selection.AllowMultipleSelectOfSameEntity = True

      pm_Selection.Height = 50

      pm_Selection.SetSelectionFilters filters

      

      pm_Selection2.SingleEntityOnly = False

      pm_Selection2.AllowMultipleSelectOfSameEntity = True

      pm_Selection2.Height = 50

      pm_Selection2.SetSelectionFilters filters

          

      ' Create a combo box

      controlType = swControlType_Combobox

      caption = ""

      alignment = swControlAlign_Indent

      options = swControlOptions_Visible + _

          swControlOptions_Enabled

      tip = "Select a value from the dropdown"

      Set 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.AddItems (listItems)

                pm_Combo.CurrentSelection = 0

                

            End If

    

     ' Create a list box

      controlType = swControlType_Listbox

      caption = ""

      alignment = swControlAlign_Indent

      options = swControlOptions_Visible + _

          swControlOptions_Enabled

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

      Set pm_List = pm_Group.AddControl(ListID, _

          controlType, caption, alignment, options, tip)

      

      pm_List.Style = 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.AddItems (listItems)

                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

 

Private Sub PropertyManagerPage2Handler7_AfterActivation()

End Sub

Private Sub PropertyManagerPage2Handler7_AfterClose()

    'Destroy the class

    Set pm = Nothing

End Sub

Private Function PropertyManagerPage2Handler7_OnActiveXControlCreated(ByVal Id As Long, ByVal Status As Boolean) As Long

End Function

Private Sub PropertyManagerPage2Handler7_OnButtonPress(ByVal Id As Long)

End Sub

Private Sub PropertyManagerPage2Handler7_OnCheckboxCheck(ByVal Id As Long, ByVal Checked As Boolean)

End Sub

Private Sub PropertyManagerPage2Handler7_OnClose(ByVal Reason As Long)

If Reason = swPropertyManagerPageClose_Cancel Then

    'Cancel button was clicked

    ClickedCancel = True

ElseIf Reason = swPropertyManagerPageClose_Okay Then

    'OK button was clicked

    ClickedCancel = False

End If

End Sub

Private Sub PropertyManagerPage2Handler7_OnComboboxEditChanged(ByVal Id As Long, ByVal Text As String)

End Sub

Private Sub PropertyManagerPage2Handler7_OnComboboxSelectionChanged(ByVal Id As Long, ByVal Item As Long)

End Sub

Private Sub PropertyManagerPage2Handler7_OnGroupCheck(ByVal Id As Long, ByVal Checked As Boolean)

End Sub

Private Sub PropertyManagerPage2Handler7_OnGroupExpand(ByVal Id As Long, ByVal Expanded As Boolean)

End Sub

Private Function PropertyManagerPage2Handler7_OnHelp() As Boolean

End Function

Private Function PropertyManagerPage2Handler7_OnKeystroke(ByVal Wparam As Long, ByVal Message As Long, ByVal Lparam As Long, ByVal Id As Long) As Boolean

End Function

Private Sub PropertyManagerPage2Handler7_OnListboxSelectionChanged(ByVal Id As Long, ByVal Item As Long)

End Sub

Private Function PropertyManagerPage2Handler7_OnNextPage() As Boolean

End Function

Private Sub PropertyManagerPage2Handler7_OnNumberboxChanged(ByVal Id As Long, ByVal Value As Double)

End Sub

Private Sub PropertyManagerPage2Handler7_OnOptionCheck(ByVal Id As Long)

End Sub

Private Sub PropertyManagerPage2Handler7_OnPopupMenuItem(ByVal Id As Long)

End Sub

Private Sub PropertyManagerPage2Handler7_OnPopupMenuItemUpdate(ByVal Id As Long, retVal As Long)

End Sub

Private Function PropertyManagerPage2Handler7_OnPreview() As Boolean

End Function

Private Function PropertyManagerPage2Handler7_OnPreviousPage() As Boolean

End Function

Private Sub PropertyManagerPage2Handler7_OnRedo()

End Sub

Private Sub PropertyManagerPage2Handler7_OnSelectionboxCalloutCreated(ByVal Id As Long)

End Sub

Private Sub PropertyManagerPage2Handler7_OnSelectionboxCalloutDestroyed(ByVal Id As Long)

End Sub

Private Sub PropertyManagerPage2Handler7_OnSelectionboxFocusChanged(ByVal Id As Long)

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

End Sub

Private Sub PropertyManagerPage2Handler7_OnSelectionboxListChanged(ByVal Id As Long, ByVal Count As Long)

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

    pm_Page.SetCursor (swPropertyManagerPageCursors_Advance)

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

End Sub

Private Sub PropertyManagerPage2Handler7_OnSliderPositionChanged(ByVal Id As Long, ByVal Value As Double)

End Sub

Private Sub PropertyManagerPage2Handler7_OnSliderTrackingCompleted(ByVal Id As Long, ByVal Value As Double)

End Sub

Private Function PropertyManagerPage2Handler7_OnSubmitSelection(ByVal Id As Long, ByVal Selection As Object, ByVal SelType As Long, ItemText As String) As Boolean

    PropertyManagerPage2Handler7_OnSubmitSelection = True

End Function

Private Function PropertyManagerPage2Handler7_OnTabClicked(ByVal Id As Long) As Boolean

End Function

Private Sub PropertyManagerPage2Handler7_OnTextboxChanged(ByVal Id As Long, ByVal Text As String)

End Sub

Private Sub PropertyManagerPage2Handler7_OnUndo()

End Sub

Private Sub PropertyManagerPage2Handler7_OnWhatsNew()

End Sub

Private Sub PropertyManagerPage2Handler7_OnLostFocus(ByVal Id As Long)

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

End Sub

Private Sub PropertyManagerPage2Handler7_OnGainedFocus(ByVal Id As Long)

   Dim varArray As Variant

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

   varArray = pm_List.GetSelectedItems

   pm_Combo.CurrentSelection = varArray(0)

End Sub

________________________________________________________________________________________



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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Create PropertyManager Page Example (VBA)
*Comment:  
*   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:



x

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
x

Web Help Content Version: API Help (English only) 2010 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.