Set Material Property Name Example (VBA)
This example shows how to set a part's material property name.
'------------------------------------------------------------------
'
' Preconditions: Part document is open.
'
' Postconditions: Model and part material property name
changed to Alloy Steel.
'
'------------------------------------------------------------------
Option Explicit
Sub main()
Dim
swApp As
SldWorks.SldWorks
Dim
swModel As
SldWorks.ModelDoc2
Dim
swPart As
SldWorks.PartDoc
Dim
i As
Long
Dim
bRet As
Boolean
Set
swApp = Application.SldWorks
Set
swModel = swApp.ActiveDoc
Set
swPart = swModel
Debug.Print
"File = " & swModel.GetPathName
Debug.Print
" Old
model material =
" & swModel.MaterialIdName
Debug.Print
" Old
part material
=
" & swPart.MaterialIdName
'
Apply new material. This operation overwrites the information in
'
ModelDoc2::MaterialIdName and PartDoc::MaterialIdName.
swPart.SetMaterialPropertyName "SolidWorks
Materials.sldmat", "Alloy Steel"
Debug.Print
" New
model material =
" & swModel.MaterialIdName
Debug.Print
" New
part material
=
" & swPart.MaterialIdName
End Sub
'---------------------------------------