Hide Table of Contents

Change Texture on Face in Specified Configuration Example (VBA)

This example shows how to change the texture on the selected face in the specified configuration

 

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

'

' Preconditions:

'       (1) Part or assembly is open.

'       (2) Specified configuration exists.

'       (3) Face is selected.

'

' Postconditions: Texture is applied to that face in that configuration.

'

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

Option Explicit

 

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swSelMgr As SldWorks.SelectionMgr

Dim swModelDocExt As SldWorks.ModelDocExtension

Dim face As SldWorks.face2

Dim texture As SldWorks.texture

Dim boolstatus As Boolean

Dim configName As String

Dim bAll As Boolean

Dim configVar As Variant

Dim namStr As String

 

Sub main()

 

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swSelMgr = swModel.SelectionManager

Set swModelDocExt = swModel.Extension

 

configName = "Default"

bAll = True

 

Set face = swSelMgr.GetSelectedObject5(1)

Dim configArr(0 To 0) As String

configArr(0) = configName

configVar = configArr

 

'Get existing texture on this face

Set texture = face.GetTexture(configName)

If Not texture Is Nothing Then

    Debug.Print "MATERIAL -> " & texture.MaterialName

    Debug.Print "SCALE -> " & texture.scaleFactor

    Debug.Print "Angle -> " & texture.angle

    'Change texture on this face

    texture.angle = 340

    texture.scaleFactor = 25

    texture.MaterialName = "<SystemTexture>\images\textures\plastic\brushed\bblue.jpg"

    boolstatus = face.SetTexture(configName, texture)

Else

    'If no texture exists on this face, then apply this texture to it

    namStr = "<SystemTexture>\images\textures\pattern\checker2.jpg"

    Set texture = swModelDocExt.CreateTexture(namStr, 5, 45, False)

    boolstatus = face.SetTexture(configName, texture)

End If

 

namStr = texture.MaterialName

Debug.Print texture.GetSystemTextureName(namStr, 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 Texture on Face in Specified Configuration 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) 2014 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.