SOLIDWORKS PDM API to get referenced files
Posted: Mon Apr 24, 2023 12:56 pm
I would like to create a doc file from PDM templates capabilities. The ideia is create a ECO where all infomations regarding this ECO was provided by user in a datacard and the new document would be filled with these informations. One field in this ECO doc should be to list the referenced files displayed in contain tab. In my searches i have found the API described below but doesn't work. I'm not fluent in API but i would like to know if somone can help me.
If ThisDocument.ReadOnly = False Then
Dim strDocumentPath As String
strDocumentPath = ThisDocument.FullName
Dim oVault As New EdmVault5
oVault.LoginAuto oVault.GetVaultNameFromPath(strDocumentPath), 0
Dim oFile As IEdmFile6
Dim oFolder As IEdmFolder6
Set oFile = oVault.GetFileFromPath(strDocumentPath, oFolder)
Dim projName As String
If oFile Is Nothing Then
MsgBox "File not in vault", vbCritical
Else
Dim oRef As IEdmReference5
Set oRef = oFile.GetReferenceTree(oFolder.ID, 0)
Dim mytable As Table
Set mytable = ActiveDocument.Tables(2)
mytable.Cell(1, 1).Select
Selection.Delete
Selection.InsertAfter Text:=AddReferences(oRef, 0, projName)
End If
End If
End Sub
Private Function AddReferences(file As IEdmReference5, ByVal indent As Long, ByRef projName As String) As String
Dim msg As String
msg = String(indent, " ")
msg = msg + IIf(indent > 0, file.Name, "") + vbLf
Dim isTop As Boolean
isTop = True
If indent > 0 Then isTop = False
indent = indent + 4
Dim pos As IEdmPos5
Set pos = file.GetFirstChildPosition(projName, isTop, True, 0)
Dim ref As IEdmReference5
While Not pos.IsNull
Set ref = file.GetNextChild(pos)
msg = msg + AddReferences(ref, indent, projName)
msg = msg + ref.file.Name + vbLf
Wend
AddReferences = msg
End Function
Private Sub Document_Open()
If ThisDocument.ReadOnly = False Then
Selection.WholeStory
Selection.Fields.Update
AutoOpen
End If
End Sub