Hide Table of Contents

Create PropertyManager Page With Many Controls Example (VBA)

This example shows how to create a PropertyManager page with many controls.

Macro

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

'

' Precondition: SolidWorks is running.

'

' Postconditions: A PropertyManager page with

'               many controls is created.

'

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

Dim swApp                   As SldWorks.SldWorks

Dim swPart                  As SldWorks.PartDoc

 

'The application's PropertyManager page

Dim swPage                  As PropMgr

Sub main()

    Dim nRetVal             As Long

    Set swApp = CreateObject("SldWorks.Application")

    'Make sure that there is a model to which to

    'the page; if there is no model, then get rid

    'of references to any previous pages

    If swApp.ActiveDoc Is Nothing Then

        Set swPart = swApp.NewPart

        Set swPage = Nothing

    End If

    

    'If there is no page, create a new one and show it

    'If there is a page, then show it

    If swPage Is Nothing Then

        Set swPage = New PropMgr

        swPage.Show

    Else

        swPage.Show

    End If

End Sub

Back to top

PropMgr

'This class defines the PropertyManager page and its controls

Option Explicit

'The PropertyManager page

Private m_Page                  As SldWorks.PropertyManagerPage2

'The two groups that will contain the controls

Private m_Group1                As SldWorks.PropertyManagerPageGroup

Private m_Group2                As SldWorks.PropertyManagerPageGroup

'The controls on the page

Private m_Text                  As SldWorks.PropertyManagerPageTextbox

Private m_Check                 As SldWorks.PropertyManagerPageCheckbox

Private m_Option1               As SldWorks.PropertyManagerPageOption

Private m_Option2               As SldWorks.PropertyManagerPageOption

Private m_Option3               As SldWorks.PropertyManagerPageOption

Private m_List                  As SldWorks.PropertyManagerPageListbox

Private m_Selection1            As SldWorks.PropertyManagerPageSelectionbox

Private m_Selection2            As SldWorks.PropertyManagerPageSelectionbox

Private m_Number                As SldWorks.PropertyManagerPageNumberbox

Private m_Combo                 As SldWorks.PropertyManagerPageCombobox

Private m_ClearSelection        As SldWorks.PropertyManagerPageCheckbox

Private m_Button                As SldWorks.PropertyManagerPageButton

Private m_Label                 As SldWorks.PropertyManagerPageLabel

Private m_pActiveXControl       As SldWorks.PropertyManagerPageActiveX

'Whether the second group is active

Private m_bGroup2               As Boolean

'The IDs for all of the controls

Const ID_GROUP1                 As Long = 1

Const ID_TEXT                   As Long = 2

Const ID_CHECK                  As Long = 3

Const ID_OPTION1                As Long = 4

Const ID_OPTION2                As Long = 5

Const ID_OPTION3                As Long = 6

Const ID_LIST                   As Long = 7

Const ID_GROUP2                 As Long = 8

Const ID_SELECTION1             As Long = 9

Const ID_SELECTION2             As Long = 10

Const ID_NUMBER                 As Long = 11

Const ID_COMBO                  As Long = 12

Const ID_BUTTON                 As Long = 13

Const ID_LABEL                  As Long = 14

Const ID_ACTIVEX                As Long = 15

'Create the page and place all of the controls on it

Private Sub Layout()

    Dim swApp                   As SldWorks.SldWorks

    'Objects needed to create the PropertyManager page

    Dim pageHdlr                As New PropMgrHdlr

    Dim swPage                  As SldWorks.PropertyManagerPage2

    Dim swControl               As SldWorks.PropertyManagerPageControl

    

    Dim pCalCtrl                As MSACAL.Calendar

    

    Dim title                   As String

    Dim message                 As String

    Dim caption                 As String

    Dim tip                     As String

    Dim listItems(3)            As String

    

    Dim buttonTypes             As Long

    Dim Id                      As Long

    Dim options                 As Long

    Dim filterArray(1)          As Long

    Dim errors                  As Long

    

    Dim controlType             As Integer

    Dim alignment               As Integer

    

    Dim bRet                    As Boolean

    

    'Access SolidWorks

    Set swApp = GetObject(, "SldWorks.Application")

    

    'Initialize the page handler

    'Pass a reference to this PropertyManager page

    pageHdlr.Init Me

    

    'Set some variables for the page

    title = "Sample PropertyManager"

    buttonTypes = swPropertyManager_OkayButton + swPropertyManager_CancelButton

   

   'Create the PropertyManager page

    Set m_Page = swApp.CreatePropertyManagerPage(title, buttonTypes, pageHdlr, errors)

    

    'Make sure that it was created properly

    If errors = swPropertyManagerPage_Okay Then

        

        'Initial set up of the dialog

        message = "Information message that can be displayed as necessary."

        m_Page.SetMessage message, swImportantMessageBox

        'Begin adding the controls to the PropertyManager page

        'GROUP BOX ------------------------------------------------------------------

        Id = ID_GROUP1

        caption = "Group &1"

        options = swGroupBoxOptions_Visible + swGroupBoxOptions_Expanded

        Set m_Group1 = m_Page.AddGroupBox(Id, caption, options)

        If Not m_Group1 Is Nothing Then

            'Place these controls in the first group

            'CONTROL Textbox  --------------------------------------------------------------------

            Id = ID_TEXT

            controlType = swControlType_Textbox

            caption = "Sample text box"

            alignment = swControlAlign_Indent

            options = swControlOptions_Visible + swControlOptions_Enabled

            tip = "Text box"

            Set swControl = Nothing

            Set swControl = m_Group1.AddControl(Id, controlType, caption, alignment, options, tip)

            If Not swControl Is Nothing Then

                Set m_Text = swControl

               'm_Text.Style = swconst.swPropMgrPageTextBoxStyle_e.

            End If

            'CONTROL Checkbox  --------------------------------------------------------------------

            Id = ID_CHECK

            controlType = swControlType_Checkbox

            caption = "Sample check box"

            alignment = swControlAlign_Indent

            options = swControlOptions_Visible + swControlOptions_Enabled

            tip = "Check box"

            Set swControl = m_Group1.AddControl(Id, controlType, caption, alignment, options, tip)

            If Not swControl Is Nothing Then

                Set m_Check = swControl

                m_Check.Checked = False

            End If

            'CONTROL Option  --------------------------------------------------------------------

            Id = ID_OPTION1

            controlType = swControlType_Option

            caption = "Radio button 1"

            alignment = swControlAlign_Indent

            options = swControlOptions_Visible + swControlOptions_Enabled

            tip = "Option 1"

            Set swControl = m_Group1.AddControl(Id, controlType, caption, alignment, options, tip)

            If Not swControl Is Nothing Then

                Set m_Option1 = swControl

                m_Option1.Checked = True

            End If

            'CONTROL Option  --------------------------------------------------------------------

            Id = ID_OPTION2

            controlType = swControlType_Option

            caption = "Radio button 2"

            alignment = swControlAlign_Indent

            options = swControlOptions_Visible + swControlOptions_Enabled

            tip = "Option 2"

            Set swControl = m_Group1.AddControl(Id, controlType, caption, alignment, options, tip)

            If Not swControl Is Nothing Then

                Set m_Option2 = swControl

                m_Option2.Checked = False

            End If

            'CONTROL Option  --------------------------------------------------------------------

            Id = ID_OPTION3

            controlType = swControlType_Option

            caption = "Radio button 3"

            alignment = swControlAlign_Indent

            options = swControlOptions_Visible + swControlOptions_Enabled

            tip = "Option 3"

            Set swControl = m_Group1.AddControl(Id, controlType, caption, alignment, options, tip)

            If Not swControl Is Nothing Then

                Set m_Option3 = swControl

                m_Option3.Checked = False

            End If

            'CONTROL List box  -------------------------------------------------------------------

            Id = ID_LIST

            controlType = swControlType_Listbox

            caption = "Sample list box"

            alignment = swControlAlign_Indent

            options = swControlOptions_Visible + swControlOptions_Enabled

            tip = "List box"

            Set swControl = m_Group1.AddControl(Id, controlType, caption, alignment, options, tip)

            If Not swControl Is Nothing Then

                Set m_List = swControl

                

                m_List.Height = 50

                

                listItems(0) = "One Fish"

                listItems(1) = "Two Fish"

                listItems(2) = "Red Fish"

                listItems(3) = "Blue Fish"

                m_List.AddItems (listItems)

                

                m_List.CurrentSelection = 2

            End If

            

            'CONTROL Button --------------------------------------------------------------------

            Id = ID_BUTTON

            controlType = swControlType_Button

            caption = "Sample button"

            alignment = swControlAlign_Indent

            options = swControlOptions_Visible + swControlOptions_Enabled

            tip = "Button"

            Set swControl = m_Group1.AddControl(Id, controlType, caption, alignment, options, tip)

            If Not swControl Is Nothing Then

                Set m_Button = swControl

            End If

        End If

        'GROUP BOX ------------------------------------------------------------------

        Id = ID_GROUP2

        caption = "Group &2"

        options = swGroupBoxOptions_Visible + swGroupBoxOptions_Checkbox '+ swGroupBoxOptions_Expanded + swGroupBoxOptions_Checked

        m_bGroup2 = False  'Mark that the second group is disabled

        Set m_Group2 = m_Page.AddGroupBox(Id, caption, options)

        If Not m_Group2 Is Nothing Then

            'Place these controls in the second group

            'CONTROL Label --------------------------------------------------------------------

            Id = ID_LABEL

            controlType = swControlType_Label

            caption = "Sample label"

            alignment = swControlAlign_Indent

            options = swControlOptions_Visible + swControlOptions_Enabled

            tip = "Label"

            Set swControl = m_Group2.AddControl(Id, controlType, caption, alignment, options, tip)

            If Not swControl Is Nothing Then

                Set m_Label = swControl

            End If

            'CONTROL Selection box  --------------------------------------------------------------

            Id = ID_SELECTION1

            controlType = swControlType_Selectionbox

            caption = "Sample selection box"

            alignment = swControlAlign_Indent

            options = swControlOptions_Visible + swControlOptions_Enabled

            tip = "Select faces and vertices"

            Set swControl = m_Group2.AddControl(Id, controlType, caption, alignment, options, tip)

            If Not swControl Is Nothing Then

                Set m_Selection1 = swControl

                

                filterArray(0) = swSelFACES

                filterArray(1) = swSelVERTICES

                m_Selection1.SetSelectionFilters (filterArray)

                

                m_Selection1.SingleEntityOnly = True

                m_Selection1.Height = 50

                m_Selection1.mark = 1

            End If

            'CONTROL Selection box  --------------------------------------------------------------

            Id = ID_SELECTION2

            controlType = swControlType_Selectionbox

            caption = "Sample selection box"

            alignment = swControlAlign_Indent

            options = swControlOptions_Visible + swControlOptions_Enabled

            tip = "Select faces and vertices"

            Set swControl = m_Group2.AddControl(Id, controlType, caption, alignment, options, tip)

            If Not swControl Is Nothing Then

                Set m_Selection2 = swControl

                

                filterArray(0) = swSelFACES

                filterArray(1) = swSelVERTICES

                m_Selection2.SetSelectionFilters (filterArray)

                

                m_Selection2.SingleEntityOnly = True

                m_Selection2.Height = 50

                m_Selection2.mark = 2

            End If

            'CONTROL Number box  -----------------------------------------------------------------

            Id = ID_NUMBER

            controlType = swControlType_Numberbox

            caption = "Sample number box"

            alignment = swControlAlign_Indent

            options = swControlOptions_Visible + swControlOptions_Enabled

            tip = "Number box"

            Set swControl = m_Group2.AddControl(Id, controlType, caption, alignment, options, tip)

            If Not swControl Is Nothing Then

                Set m_Number = swControl

                m_Number.SetRange2 swNumberBox_Length, -0.01, 0.01, True, 0.00001, 0.0001, 0.00005

                m_Number.Value = 0.01

                m_Number.Style = swPropMgrPageNumberBoxStyle_e.swPropMgrPageNumberBoxStyle_Thumbwheel

                Debug.Print m_Number.Style

                

            End If

            'CONTROL Combo box  ------------------------------------------------------------------

            Id = ID_COMBO

            controlType = swControlType_Combobox

            caption = "Sample combo list box"

            alignment = swControlAlign_Indent

            options = swControlOptions_Visible + swControlOptions_Enabled

            tip = "Combo box"

            Set swControl = m_Group2.AddControl(Id, controlType, caption, alignment, options, tip)

            If Not swControl Is Nothing Then

                Set m_Combo = swControl

                

                m_Combo.Height = 50

                

                listItems(0) = "One Fish"

                listItems(1) = "Two Fish"

                listItems(2) = "Red Fish"

                listItems(3) = "Blue Fish"

                m_Combo.AddItems (listItems)

                

                m_Combo.CurrentSelection = 1

            End If

            

            ' START ActiveX stuff

            Set m_pActiveXControl = m_Group2.AddControl(ID_ACTIVEX, _

                                        swControlType_ActiveX, _

                                        "ActiveX Control", _

                                        swControlAlign_LeftEdge, _

                                        swControlOptions_Visible + swControlOptions_Enabled, _

                                        "ActiveX control tip")

            m_pActiveXControl.Height = 250

    

            bRet = m_pActiveXControl.SetClass("MSCAL.calendar", "")

            

            ' Will return NULL because control is not

            ' created until PropertyManager page is shown

            'Set pCalCtrl = m_pActiveXControl.GetControl

            '

            'pCalCtrl.Month = 10

            ' END ActiveX stuff

            

        End If

    Else

        swApp.SendMsgToUser2 "There was an error creating the Property Manager page.", swMbInformation, swMbOk

    End If

End Sub

'Display the PropertyManager page

Public Sub Show()

    Dim nRetVal                 As Long

    Dim pCalCtrl                As MSACAL.Calendar

    

    nRetVal = m_Page.Show

    

    ' START ActiveX stuff

    Set pCalCtrl = m_pActiveXControl.GetControl

    

    pCalCtrl.Month = 10

    ' END ActiveX stuff

End Sub

'Generate the PropertyManagre page and its controls

Private Sub Class_Initialize()

    Layout

End Sub

'Callback called by PropertyManagerPage2Handler5_OnButtonPress

'in the PropertyManagerPage2Handler5 class

'This implementation just clears the selections

Public Sub OnButtonPressed(ByVal Id As Long)

    Dim swApp                   As SldWorks.SldWorks

    Dim swModel                 As SldWorks.ModelDoc2

    Dim swSelMgr                As SldWorks.SelectionMgr

    Dim nSelCount               As Long

    Dim i                       As Long

    If Id = ID_BUTTON Then

        Set swApp = GetObject(, "SldWorks.Application")

        Set swModel = swApp.ActiveDoc

        Set swSelMgr = swModel.SelectionManager

        

        nSelCount = swSelMgr.GetSelectedObjectCount

        For i = 1 To nSelCount

            Debug.Print "SelMark(" + Str(i) + ") =" + Str(swSelMgr.GetSelectedObjectMark(i))

        Next i

        

        swModel.ClearSelection2 True

    End If

End Sub

Back to top

 

PropMgrHdlr

' This file is the implementation of the PropertyManagerPage2Handler5

' interface

' Each of these methods is called when its corresponding notification is fired

' from within SolidWorks

' It is customary to have notifications use callback

' functions defined within the main application to perform

' any desired actions

Option Explicit

Implements PropertyManagerPage2Handler

'Variable that provides access to the PropertyManager page

Dim m_PageObj                   As PropMgr

'This method is called to initialize the handler

Public Sub Init(pageObj As PropMgr)

    Set m_PageObj = pageObj

End Sub

Private Sub PropertyManagerPage2Handler5_AfterClose()

End Sub

'******************************************************************************'

'These methods are the implementations of the SolidWorks notifications

 

Private Sub PropertyManagerPage2Handler5_OnButtonPress(ByVal Id As Long)

    m_PageObj.OnButtonPressed (Id)

End Sub

 

Private Sub PropertyManagerPage2Handler5_OnCancel()

End Sub

 

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

End Sub

 

Private Sub PropertyManagerPage2Handler5_OnClose(ByVal Reason As Long)

End Sub

 

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

End Sub

 

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

End Sub

 

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

End Sub

 

Private Function PropertyManagerPage2Handler5_OnHelp() As Boolean

End Function

 

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

End Sub

 

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

End Sub

 

Private Sub PropertyManagerPage2Handler5_OnOK()

End Sub

 

Private Sub PropertyManagerPage2Handler5_OnOptionCheck(ByVal Id As Long)

End Sub

 

Private Sub PropertyManagerPage2Handler5_OnSelectionboxFocusChanged(ByVal Id As Long)

End Sub

 

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

End Sub

 

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

End Sub

 

 

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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Create PropertyManager Page With Many Controls 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) 2013 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.