Get Material Example (VBA)
This example shows how to get the material for a part.
'---------------------------------------
'
' Preconditions:
' (1)
Part document is open and multiple configurations of the part exist.
' (2)
A material has been applied to the part.
'
' Postconditions: None
'
'----------------------------------------
Option Explicit
Sub main()
Dim
swApp As
SldWorks.SldWorks
Dim
swModel As
SldWorks.ModelDoc2
Dim
swPart As
SldWorks.PartDoc
Dim
sMatName As
String
Dim
sMatDB As
String
Dim
bRet As
Boolean
Set
swApp = Application.SldWorks
Set
swModel = swApp.ActiveDoc
Set
swPart = swModel
sMatName
= swPart.GetMaterialPropertyName2("Default",
sMatDB)
Debug.Print
"File = " & swModel.GetPathName
Debug.Print
" Material
= " & sMatName & " (" & sMatDB & ")"
End Sub
'---------------------------------------