1

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

4
  • Your filename filePath = "D:\Comp\Projects\XYZABC.sldprt.cvd" is weird. That's not a SolidWorks file. Are you sure about that .cvd extension in the filename? Commented Jun 13, 2024 at 15:39
  • Yes, this is a virtual document that can be generated within SolidWorks PDM, specifically for referencing materials such as datasheets or scanned blueprints. Commented Jun 14, 2024 at 6:20
  • Well maybe, "this is a virtual document" is the answer to your problem, but I'm really not able to test it. Commented Jun 14, 2024 at 8:12
  • I get the same with a .sldasm file. Commented Jun 14, 2024 at 10:54

1 Answer 1

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)
answered Apr 1, 2025 at 10:47
Sign up to request clarification or add additional context in comments.

1 Comment

There is another possibility than using SolidWorks marco, namely a Windows Script file (*.wsf), where you add the PDMWorks Enterprise Type Library as reference. Then you are able can use correct object types.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.