Get Material Property Names Example (VBA)
This example shows how to get the material names in the active part
document.
'---------------------------------------
Option Explicit
Sub main()
Dim
swApp As
SldWorks.SldWorks
Dim
swModel As
SldWorks.ModelDoc
Dim
swPart As
SldWorks.PartDoc
Dim
swConfig As
SldWorks.configuration
Dim
swBody As
SldWorks.Body
Dim
swFace As
SldWorks.face
Dim
sMatName As
String
Dim
sMatUserName As
String
Dim
i As
Long
Dim
bRet As
Boolean
Set
swApp = Application.SldWorks
Set
swModel = swApp.ActiveDoc
Set
swPart = swModel
Set
swConfig = swModel.GetActiveConfiguration
Set
swBody = swPart.Body
Set
swFace = swBody.GetFirstFace
Debug.Print
"SldWorks::RevNum =
" & swApp.RevisionNumber
Debug.Print
" File
= " & swModel.GetPathName
Debug.Print
" ConfigName
=
" & swConfig.Name
Debug.Print
" Part::MatIdName
=
" & swPart.MaterialIdName
Debug.Print
" Part::MatUserName
=
" & swPart.MaterialUserName
Debug.Print
""
Do
While Not swFace Is Nothing
sMatName
= swFace.MaterialIdName
sMatUserName
= swFace.MaterialUserName
If
sMatName <> "" Then
Debug.Print
" Face::MatIdName("
& i & ") =
" & sMatName
End
If
If
sMatUserName <> "" Then
Debug.Print
" Face::MatUserName("
& i & ") =
" & sMatUserName
End
If
i
= i + 1
Set
swFace = swFace.GetNextFace
Loop
End Sub