Getting the latest version of a file from the EPDM vault

Hello

I'm opening this new post in relation to another one: http://www.lynkoa.com/forum/import-export-formats-neutres/lien-vba-epdm because after the conversations I understood that my problem was elsewhere.

I made a macro in order to facilitate the use of CAD files by my colleagues I am coming to the end of my goals, I have only one blocking point: the files are stored in the EPDM vault of my company, following tests I noticed that my macro only worked when the files were extracted or were already present in the local cache.

So I'd like to find a way in vba to automatically  do "Get the latest version of the file" because if this version is not present my code doesn't work. There doesn't seem to be any automatic getting programmed.

Thank you

How does the best answer on your other post not solve your problem?

Beware of subtlety:

Get latest version (including children in future version)

and:

Get the as-built version (same for kids)

When we look at EPDM jobs, this parameter is there, and we often set it to "as built"

 

Example:

ASM = version 3/3

PRT1 = 5/5

PRT2 = 9/9

If the ASM was built with

PRT1 = 4/5

PRT2 = 7/9

 

If you do "get latest version" it will take you:

ASM = 3/3

PRT1 = 5/5

PRT2 = 9/9

so you won't be in "as built"!

Hello

You must use the Getfile function of the IedmFile method

And potentially check the number of versions beforehand in order to know which one to open.

I'm answering you here because in the other topic it's going to be lost for this specific need.

Below is the GetFile method given by the PDM 2009 API help in vba

Private Sub GetMyFile(vault As EdmVault5)
On Error GoTo ErrHand

  Dim folder As IEdmFolder5
  Set folder = vault.RootFolder
  Dim file As IEdmFile5
  Set file = folder.GetFile("MyFile.txt")
  file.GetFileCopy Me.hWnd, 0, folder.ID
  Exit Sub

ErrHand:
  Dim ename As String
  Dim edesc As String
  vault.GetErrorString Err.Number, ename, edesc
  MsgBox ename + vbLf + edesc
End Sub

 

KVuilleumier because it's a good answer but it doesn't fix my problem, the error persists.

olivier42 I now understand the subtlety but my pieces are not in an assembly, I only open parts. In addition, these parts are being put in the safe precisely to avoid any new modifications because they are standards. If one day there are potential changes due to new means of production, this will have to be approved by the management and only then will the changes be made. And these will have to be brought to all files using these parts (if there are any).

These parts are in the vault because they are produced so we want to keep track of them but not modified. However, my colleagues may look at them and make a copy of them to make a product that we call "special", but in this case it will be a new file.

Cyril.f I'm already thinking of using this function through this line:

Set File = Vault.GetFileFromPath("C:\SOLIDWORKS Data\Schaublin_RODS\04-Dessins Solidworks\01-Dessins pieces\80-\80-5\CAO_W25_80-5", Folder)

I think my problem is that when you open a part or even view it in the EPDM explorer MUST load "the latest version to put it in the cache. But in my case no one physically clicks on the file to load it because it's a macro so in my cache I don't have any version so for him it doesn't exist.

You miss it: go away. GetFileCopy

The snippet of code I put contains everything to use this function from the getFileFromPath method.

If I understand correctly, I have to create a new function where I have to write the code you indicated and then call this function just before opening my room?

But when do I put the path (the location) of my file or folder please? Instead of MyFile.txt?

Edit:

Sub GetMyFile(vault As EdmVault5)
    On Error GoTo ErrHand
    
      Dim folder As IEdmFolder5
      Set folder = vault.GetFolderFromPath("C:\SOLIDWORKS Data\Mon_coffre\04-Dessins Solidworks\01-Dessins pieces\80-\80-5")
      Dim file As IEdmFile5
      Set file = folder.GetFile("CAO_W25_80-5")
      file.GetFileCopy Me.HWnd, 0, folder.ID
      Exit Sub
    
ErrHand:
      Dim ename As String
      Dim edesc As String
      vault.GetErrorString Err.Number, ename, edesc
      MsgBox ename + vbLf + edesc
End Sub

I wrote this for myself, it's just, isn't it?

Edit bis:

When I launch the macro it stops on Me.Hwnd and an error appears "Method not found". Is there a reference to add?

Added file. GetFileCopy 0, 0, folder.ID under your Set file. On the other hand, you need to retrieve the ID of the folder in which the file is located.

Set folder = vault.getfolderfrompath(C:\xxx")

I just got the same error message as you, try adding the extension to your filename (.sldprt for a part).

Kind regards

First of all, thank you for your interest in this post!

So I added the extension of my file (.sldprt) I also added what Cyril is talking about.f  

I finally get this code 

 Private Sub CBox_etat_Click()

    'Déclaration des varaibles nécessaires
     Dim Part                As SldWorks.ModelDoc2
     Dim boolstatus          As Boolean
     Dim longstatus          As Long
     Dim longwarnings        As Long
     Dim swModel             As ModelDoc2
     Dim swDesignTable       As SldWorks.DesignTable
     Dim xlWS                As Worksheet
     Dim DebutDesignation    As Range
     Dim r                   As Range
     Dim Vault               As New EdmVault5
     Dim File                As IEdmFile5
     Dim Folder              As IEdmFolder5
     
     Vault.LoginAuto "Schaublin_RODS", 0

     If Info_general.CBox_type.Value = ("Pince W25") Then
        'Ouverture du fichier correspond au besoin choisi dans la liste
        'Chemin à changer lors du changement d'emplacement des fichiers EXEMPLE : Lors de l'insertion dans l'ePDM
         If CBox_etat.Value = ("Pince finie") Then
            Set Folder = Vault.GetFolderFromPath("C:\SOLIDWORKS Data\BE\04-Dessins Solidworks\01-Dessins pieces\80-\80-5")
            Set File = Vault.GetFileFromPath("C:\SOLIDWORKS Data\BE\04-Dessins Solidworks\01-Dessins pieces\80-\80-5\CAO_W25_80-5.SLDPRT", Folder)
            File.GetFileCopy 0, 0, Folder.ID
            Set Part = swApp.OpenDoc6("C:\SOLIDWORKS Data\BE\04-Dessins Solidworks\01-Dessins pieces\80-\80-5\CAO_W25_80-5.SLDPRT", 1, 0, "", longstatus, longwarnings)
            swApp.ActivateDoc2 "CAO_W25_80-5", False, longstatus
            
                'Activation du modèle ouvert, nécessaire pour accéder à la famille de pièces
                 Set swModel = swApp.ActiveDoc
                
                'Récupération de la famille de pièces
                 Set swDesignTable = swModel.GetDesignTable()
                
                'Si récupération correcte de la famille de pièces
                 If Not swDesignTable Is Nothing Then

It works... but only on my post (with different EPDM sessions). So that's what I feared, this macro works with documents from my local cache. This is due to the File.GetFileCopy line 0, 0, Folder.ID right?

Edit: On the other hand d.roger in your code (on the other post) you use 

Set Part = swApp.OpenDoc6(Folder.LocalPath & "/" & File.Name, 1, 2, "", longstatus, longwarnings)

And not the file path, is that normal?

The Folder.LocalPath is the name of the folder retrieved by the GetFileFromPath and the File.Name is the name of the file: it just saves me from copying and pasting and for my tests I only had one line to change, normally it has no impact. For the same reason in the line swApp.ActivateDoc2 File.Name, False, longstatus I put File.Name instead of the filename.

For the line File.GetFileCopy 0, 0, Folder.ID you can try with File.GetFileCopy HWnd, 0, Folder.ID

I just tried on another post and everything works wonders.....

It's okay, I added HWnd but it doesn't change anything, I can't run my macro on another computer.
It always gets stuck on the same line. Do you have to define HWnd as Long?

Edit: in line 

Set Part = swApp.OpenDoc6("C:\SOLIDWORKS Data\Mon_coffre\04-Dessins Solidworks\01-Dessins pieces\80-\80-5\CAO_W25_80-5.SLDPRT", 1, 0, "", longstatus, longwarnings)

You put ,1,2, what difference does it make? Stp

The 1 to say that it is a sldprt, the 2 to open it in read-only.

Is the file path the same on each computer?

"C:\SOLIDWORKS Data\Mon_coffre\04-Dessins Solidworks\01-Dessins pieces\80-\80-5\CAO_W25_80-5.SLDPRT"

Yes, it's the same path for each position. I'll put my code back if I had slipped an error while modifying

Private Sub CBox_etat_Click()

    'Déclaration des varaibles nécessaires
     Dim Part                As SldWorks.ModelDoc2
     Dim boolstatus          As Boolean
     Dim longstatus          As Long
     Dim longwarnings        As Long
     Dim swModel             As ModelDoc2
     Dim swDesignTable       As SldWorks.DesignTable
     Dim xlWS                As Worksheet
     Dim DebutDesignation    As Range
     Dim r                   As Range
     Dim Vault               As New EdmVault5
     Dim File                As IEdmFile5
     Dim Folder              As IEdmFolder5
     Dim HWnd                As Long
     
     Vault.LoginAuto "BE", 0

     If Info_general.CBox_type.Value = ("Pince W25") Then
        'Ouverture du fichier correspond au besoin choisi dans la liste
        'Chemin à changer lors du changement d'emplacement des fichiers EXEMPLE : Lors de l'insertion dans l'ePDM
         If CBox_etat.Value = ("Pince finie") Then
            
            Set File = Vault.GetFileFromPath("C:\SOLIDWORKS Data\BE\04-Dessins Solidworks\01-Dessins pieces\80-\80-5\CAO_W25_80-5.SLDPRT", Folder)
            Set Folder = Vault.GetFolderFromPath("C:\SOLIDWORKS Data\BE\04-Dessins Solidworks\01-Dessins pieces\80-\80-5")
            File.GetFileCopy HWnd, 0, Folder.ID
            Set Part = swApp.OpenDoc6("C:\SOLIDWORKS Data\BE\04-Dessins Solidworks\01-Dessins pieces\80-\80-5\CAO_W25_80-5.SLDPRT", 1, 0, "", longstatus, longwarnings)
            swApp.ActivateDoc2 "CAO_W25_80-5", False, longstatus
            
                'Activation du modèle ouvert, nécessaire pour accéder à la famille de pièces
                 Set swModel = swApp.ActiveDoc
                
                'Récupération de la famille de pièces
                 Set swDesignTable = swModel.GetDesignTable()
                
                'Si récupération correcte de la famille de pièces
                 If Not swDesignTable Is Nothing Then
                
                    'Récupération de la feuille excel
                     Set xlWS = swDesignTable.EditTable2(False)

Frankly I'm losing hope a little because I have the impression that in addition to only working on my computer, it only "loads" the file but not the associated drawings.

It's normal that it only loads the file and not the drawings, you also have to get the drawings to have them locally. If you have several files to put locally, it's better to use the CreateUtility(EdmUtility) function.EdmUtil_BatchGet) but here, in VBA, it may be a little more difficult. Here is an example in c# as an attachment.

Be careful, this is just an example corresponding to a need I had!!!


fonction_lastversion.txt

Good evening

Indeed, it only loads the file called. In vba you have to combine several actions in order to recover the parents and children of the file (depending on the type of file). GetNextChild or GetNextParent in the API Help.

The batch proposed by d.roger is not usable with vba to my knowledge. Only C# and VB.Net

 

I'm very disappointed because I think I'm very close to the solution but I don't have much time left to devote to this macro because I have to move on...

Especially since d.roger you say that it works on several workstations with this code? File  path: C:\SOLIDWORKS Data\Mon_coffre\04-Solidworks Drawings\01-Drawings pieces\80-\80-5\CAO_W25_80-5.SLDPRT because this is the path I find in the explorer (I find the same one on the other workstations) but it seems weird to me that it's on a local disk. Maybe you changed the paths? 

I don't know what to do anymore...  

Edit: d.roger could you put the complete code you used when you said it works wonders please?

Hello

Here is the test code that works perfectly for me:

Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

    Set swApp = Application.SldWorks

    Dim Vault As New EdmVault5

    Dim File As IEdmFile5
    Dim Folder As IEdmFolder5

    Vault.LoginAuto "Coffre_BE", 0

    Set File = Vault.GetFileFromPath("C:\Coffre_BE\TEST\0088880001.SLDPRT", Folder)
    
    Set Part = swApp.OpenDoc6(Folder.LocalPath & "/" & File.Name, 1, 2, "", longstatus, longwarnings)
    
    swApp.ActivateDoc2 File.Name, False, longstatus
    
    Set swModel = swApp.ActiveDoc
    
    swModel.ViewZoomtofit2

End Sub

For the file path, it's normal for it to be like a local file because it's the one from the local view of the vault, I'm just surprised that this view is in SOLIDWORKS Data.

To compensate for a possible difference in the position of the vault view between the different stations, you can start from your code, search for the vault view and then call your file path starting with Vault.rootfolder.localpath, for example:

vault1. RootFolder.LocalPath + \TEST\0088880001.SLDPRT"

example of finding vault views in C# and then connecting:

vault1 = new EdmVault5();
                
IEdmVault8 vault = (IEdmVault8)vault1;

 EdmViewInfo[] Views = null;

Vault. GetVaultViews(out Views, false);
            
comboBox1.Items.Clear();
            
foreach (EdmViewInfo View in Views)
{
      comboBox1.Items.Add(View.mbsVaultName);
}
if (comboBox1.Items.Count > 0)
{
      comboBox1.Text = (string)comboBox1.Items[0];
}

if (!vault1. IsLoggedIn)
{
      vault1. LoginAuto(comboBox1.Text, this. Handle.ToInt32());
}

Kind regards

1 Like

Hello

In your code you can remove GetFolderFromPatch since you get it in the GetFileFromPath (it will already lighten the processing and avoid copy/paste errors).

In the vault settings, do all users have access to this folder? Don't you have additional rights that make it work on your job and not on someone else?

2 Likes