MACRO LIBRARY

Change face colors with PropertyManager page

Free public access. No account or subscription required.

Files

Change face colors with PropertyManager page

Code

Modules: mMain

'Demonstrates how to change a faces color using a PropertyManager page
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
'Preconditions: part is open with a body
    
Dim swApp As SldWorks.SldWorks
Public swModel As SldWorks.ModelDoc2
Dim pmPage As clsPMP    'Can't be in sub procedure or selection doesn't work
    
'These public variables are needed because Public is not recognized between class modules
Public Const intGroupID As Integer = 0
Public Const intSelID As Integer = 1
Public Const intButtonRedID As Integer = 2
Public Const intButtonGreenID As Integer = 3
Public Const intButtonBlueID As Integer = 4
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    If swModel.GetType = swDocDRAWING Then
        MsgBox "Run in part or assembly."
        End
    End If
    
    Set pmPage = New clsPMP
    pmPage.Show swApp
End Sub

Class Modules: clsPMP

Dim pmHandler As clsPMPHandler
Dim pmPage As SldWorks.PropertyManagerPage2
Dim pmGroup As SldWorks.PropertyManagerPageGroup
Dim pmSelection As SldWorks.PropertyManagerPageSelectionbox
Dim pmButtonRed As SldWorks.PropertyManagerPageButton
Dim pmButtonGreen As SldWorks.PropertyManagerPageButton
Dim pmButtonBlue As SldWorks.PropertyManagerPageButton
Dim lngErrors As Long
    
Sub Show(swApp As SldWorks.SldWorks)
    'Create the PMP
    Set pmHandler = New clsPMPHandler
    Set pmPage = swApp.CreatePropertyManagerPage("Change Face Color", 1 + 2 + 4, _
        pmHandler, lngErrors)
    If lngErrors = 0 Then
        'Message
        pmPage.SetMessage3 "Select any number of faces and then press a button.", _
            swImportantMessageBox, swMessageBoxMaintainExpandState, "Message"
        
        'Group box
        Set pmGroup = pmPage.AddGroupBox(intGroupID, "Select faces", _
            swGroupBoxOptions_Expanded + swGroupBoxOptions_Visible)
        
        'Selection box
        Set pmSelection = pmGroup.AddControl(intSelID, swControlType_Selectionbox, _
            "Select faces", swControlAlign_Indent, swControlOptions_Visible + _
            swControlOptions_Enabled, Empty)
        pmSelection.SingleEntityOnly = True
        pmSelection.Height = 15
        pmSelection.SetSelectionFilters swSelFACES
        pmSelection.SetStandardPictureLabel swBitmapLabel_SelectFace
        
        'Command buttons
        Set pmButtonRed = pmPage.AddControl(intButtonRedID, swControlType_Button, _
            "Red", swControlAlign_Indent, swControlOptions_Visible + _
            swControlOptions_Enabled, Empty)
        Set pmButtonGreen = pmPage.AddControl(intButtonGreenID, swControlType_Button, _
            "Green", swControlAlign_Indent, swControlOptions_Visible + _
            swControlOptions_Enabled, Empty)
        Set pmButtonBlue = pmPage.AddControl(intButtonBlueID, swControlType_Button, _
            "Blue", swControlAlign_Indent, swControlOptions_Visible + _
            swControlOptions_Enabled, Empty)
    
        'Display the PMP
        pmPage.Show2 0
    Else
        Debug.Print "Error displaying PropertyManager page."
    End If
End Sub

Class Modules: clsPMPHandler

Implements PropertyManagerPage2Handler8
    
Private Sub PropertyManagerPage2Handler8_AfterActivation()
    
End Sub
    
Private Sub PropertyManagerPage2Handler8_AfterClose()
    
End Sub
    
Private Function PropertyManagerPage2Handler8_OnActiveXControlCreated(ByVal Id As Long, ByVal Status As Boolean) As Long
    
End Function
    
Private Sub PropertyManagerPage2Handler8_OnButtonPress(ByVal Id As Long)
    Dim r As Integer, g As Integer, b As Integer
    r = g = b = 0
    If Id = intButtonRedID Then r = 255
    If Id = intButtonGreenID Then g = 255
    If Id = intButtonBlueID Then b = 255
    
    Dim vMatPropValues As Variant
    vMatPropValues = swModel.MaterialPropertyValues
    swModel.SelectedFaceProperties RGB(r, g, b), vMatPropValues(3), _
        vMatPropValues(4), vMatPropValues(5), vMatPropValues(6), _
        vMatPropValues(7), vMatPropValues(8), False, Empty
End Sub
    
Private Sub PropertyManagerPage2Handler8_OnCheckboxCheck(ByVal Id As Long, ByVal Checked As Boolean)
    
End Sub
    
Private Sub PropertyManagerPage2Handler8_OnClose(ByVal Reason As Long)
    swModel.ClearSelection2 True
End Sub
    
Private Sub PropertyManagerPage2Handler8_OnComboboxEditChanged(ByVal Id As Long, ByVal Text As String)
    
End Sub
    
Private Sub PropertyManagerPage2Handler8_OnComboboxSelectionChanged(ByVal Id As Long, ByVal Item As Long)
    
End Sub
    
Private Sub PropertyManagerPage2Handler8_OnGainedFocus(ByVal Id As Long)
    
End Sub
    
Private Sub PropertyManagerPage2Handler8_OnGroupCheck(ByVal Id As Long, ByVal Checked As Boolean)
    
End Sub
    
Private Sub PropertyManagerPage2Handler8_OnGroupExpand(ByVal Id As Long, ByVal Expanded As Boolean)
    
End Sub
    
Private Function PropertyManagerPage2Handler8_OnHelp() As Boolean
    
End Function
    
Private Function PropertyManagerPage2Handler8_OnKeystroke(ByVal Wparam As Long, ByVal Message As Long, ByVal Lparam As Long, ByVal Id As Long) As Boolean
    
End Function
    
Private Sub PropertyManagerPage2Handler8_OnListboxRMBUp(ByVal Id As Long, ByVal PosX As Long, ByVal PosY As Long)
    
End Sub
    
Private Sub PropertyManagerPage2Handler8_OnListboxSelectionChanged(ByVal Id As Long, ByVal Item As Long)
    
End Sub
    
Private Sub PropertyManagerPage2Handler8_OnLostFocus(ByVal Id As Long)
    
End Sub
    
Private Function PropertyManagerPage2Handler8_OnNextPage() As Boolean
    
End Function
    
Private Sub PropertyManagerPage2Handler8_OnNumberboxChanged(ByVal Id As Long, ByVal Value As Double)
    
End Sub
    
Private Sub PropertyManagerPage2Handler8_OnOptionCheck(ByVal Id As Long)
    
End Sub
    
Private Sub PropertyManagerPage2Handler8_OnPopupMenuItem(ByVal Id As Long)
    
End Sub
    
Private Sub PropertyManagerPage2Handler8_OnPopupMenuItemUpdate(ByVal Id As Long, retval As Long)
    
End Sub
    
Private Function PropertyManagerPage2Handler8_OnPreview() As Boolean
    
End Function
    
Private Function PropertyManagerPage2Handler8_OnPreviousPage() As Boolean
    
End Function
    
Private Sub PropertyManagerPage2Handler8_OnRedo()
    
End Sub
    
Private Sub PropertyManagerPage2Handler8_OnSelectionboxCalloutCreated(ByVal Id As Long)
    
End Sub
    
Private Sub PropertyManagerPage2Handler8_OnSelectionboxCalloutDestroyed(ByVal Id As Long)
    
End Sub
    
Private Sub PropertyManagerPage2Handler8_OnSelectionboxFocusChanged(ByVal Id As Long)
    
End Sub
    
Private Sub PropertyManagerPage2Handler8_OnSelectionboxListChanged(ByVal Id As Long, ByVal Count As Long)
    
End Sub
    
Private Sub PropertyManagerPage2Handler8_OnSliderPositionChanged(ByVal Id As Long, ByVal Value As Double)
    
End Sub
    
Private Sub PropertyManagerPage2Handler8_OnSliderTrackingCompleted(ByVal Id As Long, ByVal Value As Double)
    
End Sub
    
Private Function PropertyManagerPage2Handler8_OnSubmitSelection(ByVal Id As Long, ByVal Selection As Object, ByVal SelType As Long, ItemText As String) As Boolean
    PropertyManagerPage2Handler8_OnSubmitSelection = True
End Function
    
Private Function PropertyManagerPage2Handler8_OnTabClicked(ByVal Id As Long) As Boolean
    
End Function
    
Private Sub PropertyManagerPage2Handler8_OnTextboxChanged(ByVal Id As Long, ByVal Text As String)
    
End Sub
    
Private Sub PropertyManagerPage2Handler8_OnUndo()
    
End Sub
    
Private Sub PropertyManagerPage2Handler8_OnWhatsNew()
    
End Sub
    
Private Function PropertyManagerPage2Handler8_OnWindowFromHandleControlCreated(ByVal Id As Long, ByVal Status As Boolean) As Long
    
End Function