Apply Appearance to Model Example (VBA)
This example shows how to apply an appearance to a model.
'--------------------------------------
' Preconditions: Model is open. RealView Graphics
' is
enabled.
'
' Postconditions: Appearance is applied to the model.
'--------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swAppearance As SldWorks.RenderMaterial
Dim boolstatus As Boolean
Dim strName As String
Dim nDecalID As Long
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
swModel.ClearSelection2
True
' Apply the specified appearance to add to the model
strName = "c:\Program Files\solidworks\solidworks\data\graphics\materials\metal\aluminum\brushed
aluminum.p2m"
Set swAppearance = swModelDocExt.CreateRenderMaterial(strName)
boolstatus = swAppearance.AddEntity(swModel)
boolstatus = swModelDocExt.AddRenderMaterial(swAppearance,
nDecalID)
' Rebuild the model to see the newly applied appearance
Call swModel.Rebuild(swRebuildAll)
End Sub