Hide Table of Contents

Change Color of Face Example (VBA)

This example shows how to change the color of the selected face to blue.

 

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

'

' Preconditions:

'     (1) Part or assembly is open.

'     (2) Face is selected.

'

' Postconditions: Color of selected face is changed to blue.

'

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

Option Explicit

Sub main()

    Dim swApp                       As SldWorks.SldWorks

    Dim swModel                     As SldWorks.ModelDoc2

    Dim swSelMgr                    As SldWorks.SelectionMgr

    Dim swFace                      As SldWorks.face2

    Dim vFaceProp                   As Variant

    Dim bRet                        As Boolean

    

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swSelMgr = swModel.SelectionManager

    Set swFace = swSelMgr.GetSelectedObject5(1)

    

    vFaceProp = swFace.MaterialPropertyValues

    

    If IsEmpty(vFaceProp) Then

        ' Is empty if face-level colors were not specified, so get them from underlying model

        vFaceProp = swModel.MaterialPropertyValues: Debug.Assert Not IsEmpty(vFaceProp)

    End If

    

    'Current color

    Debug.Print "RGB            = [" & vFaceProp(0) * 255# & ", " & vFaceProp(1) * 255# & ", " & vFaceProp(2) * 255# & "]"

    Debug.Print "Ambient        = " & vFaceProp(3)

    Debug.Print "Diffuse        = " & vFaceProp(4)

    Debug.Print "Specular       = " & vFaceProp(5)

    Debug.Print "Shininess      = " & vFaceProp(6)

    Debug.Print "Transparency   = " & vFaceProp(7)

    Debug.Print "Emission       = " & vFaceProp(8)

    

    ' New color

    bRet = swModel.SelectedFaceProperties( _

            RGB(0, 0, 255), _

            vFaceProp(3), vFaceProp(4), vFaceProp(5), _

            vFaceProp(6), vFaceProp(7), vFaceProp(8), _

            False, ""): Debug.Assert bRet

    

    ' Deselect face to see new color

    swModel.ClearSelection2 True

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:   Change Color of Face 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) 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.