Get Material Database Paths of Document Example (VBA)
This example shows how to get the paths and names of the material databases
for a document.
NOTE: Material database names
must be unique. Do not re-use the name of a material database.
'----------------------------------------------------
'
' Preconditions: Model is open to which a material has
been applied.
'
' Postcondition: None
'
'----------------------------------------------------
Option Explicit
Sub main()
Dim swApp As
SldWorks.SldWorks
Dim swModel As
SldWorks.ModelDoc2
Dim swPart As
SldWorks.PartDoc
Dim dbs As
Variant
Dim sMatName As
String
Dim sMatDB As
String
Dim bRet As
Boolean
Dim i As
Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swPart = swModel
dbs = swApp.GetMaterialDatabases
sMatName = swPart.GetMaterialPropertyName2("Default",
sMatDB)
For i = 0 To LBound(dbs)
If
StrComp(Left(Right(dbs(i), Len(sMatDB) + 7), Len(sMatDB)), sMatDB) = 0
Then
Debug.Print
dbs(i)
End
If
Next i
End Sub