I'm writing a simple script to count the number of referenced files giving a file in a vault of Solidworks PDM. I get a Type mismatch error in GetFileFromPath method which has the following declaration for VBA:
Visual Basic (Declaration)
Function GetFileFromPath( _
ByVal bsFilePath As System.String, _
Optional ByRef ppoRetParentFolder As IEdmFolder5 _
) As IEdmFile5
This is the script:
Dim vault
Set vault = CreateObject("ConisioLib.EdmVault")
vault.LoginAuto "VaultName", 0
If Not vault.IsLoggedIn Then
WScript.Echo "Impossible to login."
Else
Dim filePath
filePath = "D:\Comp\Projects\XYZABC.sldprt.cvd"
Dim file
Dim rootFolder
Set rootFolder = vault.RootFolder
**Set file = vault.GetFileFromPath(filePath, rootFolder)**
If Not file Is Nothing Then
Dim referenceTree
Set referenceTree = file.GetReferenceTree(0)
Dim childPosition
childPosition = referenceTree.GetFirstChildPosition("", 1, 1)
Dim numReferencedFiles
numReferencedFiles = 0
While Not childPosition.IsNull
numReferencedFiles = numReferencedFiles + 1
referenceTree.GetNextChild childPosition
Wend
WScript.Echo "Number of files referenced to file " & filePath & ": " & numReferencedFiles
Else
WScript.Echo "File doesn't exist in vault."
End If
End If
I tried to cast the filepath variable with CStr, but I got the same error
1 Answer 1
If you make that inside SolidWorks, i.e. as a SolidWorks macro, then there is the following possiblity:
- add PDMWorks Enterprise ??? Type Library in Tools/References
- define vault as IEdmVault5, not as Object
- define file as IEdmFile, not as Object
- call GetFileFromPath without the second parameter (it may still work with the second parameters, but I did not test. At least it must be defined as correct PDM type (IEdmFolder5) instead of Object)
filePath = "D:\Comp\Projects\XYZABC.sldprt.cvd"is weird. That's not a SolidWorks file. Are you sure about that.cvdextension in the filename?