Issue while getting latest version from PDM through Macro

Hello friends,

                Through forum help, I had created a macro that will find the part or assembly from PDM Vault and Gets the Latest Version of the file and be opened in the SolidWorks.

It works well for some files but not for all… Please see below for my code…

 

Dim swApp As SldWorks.SldWorks

Dim swModel As ModelDoc2

Dim myVault As EdmVault5

Dim search As IEdmSearch7

Dim result As IEdmSearchResult5

Dim epdmfile As IEdmFile5Dim epdmFolder  As IEdmFolder5

Dim DesiredFile As String

Dim ModelName As String

Dim ModelPath As String

Dim boolstatus As Boolean

Dim longstatus As Long, longwarnings As Long, longerrors As Long

 

Sub main()

Set swApp = Application.SldWorks

Set myVault = New EdmVault5

myVault.LoginAuto "PDM-VAULT", 0

 

Set search = myVault.CreateUtility(EdmUtility.EdmUtil_Search)

search.Clear

 

DesiredFile = "G2640"        ‘------------file name

 

search.FindFolders = False

search.FindFiles = True

search.FileName = DesiredFile & ".%"

search.Recursive = True

search.SetToken Edmstok_Recursive, True

Set result = search.GetFirstResult

Set epdmfile = Nothing

Set epdmFolder = Nothing

    While Not result Is Nothing

        Set epdmFolder = myVault.GetObject(EdmObjectType.EdmObject_Folder, result.ParentFolderID)

        Set epdmfile = myVault.GetObject(EdmObjectType.EdmObject_File, result.ID)

        Set result = search.GetNextResult()

        ModelName = epdmfile.Name

       

Dim eFile As IEdmFile5

        If Right(ModelName, 3) = "ASM" Then

            Set eFile = result

            eFile.GetFileCopy (0)

            ModelPath = epdmFolder.LocalPath & "\" & epdmfile.Name

            Set swModel = swApp.OpenDoc6(ModelPath, 2, 0, "", longstatus, longwarnings)

        ElseIf Right(ModelName, 3) = "PRT" Then

            Set eFile = result

            eFile.GetFileCopy (0)

            ModelPath = epdmFolder.LocalPath & "\" & epdmfile.Name

            Set swModel = swApp.OpenDoc6(ModelPath, 2, 0, "", longstatus, longwarnings)

        End If

    Wend

      Debug.Print ModelPath

End Sub

 

 

Could someone help me where I am missing…

SolidworksApi/macros