PDM Vault Version via Excel Macro

Hello 

I'll try to explain my problem as best I can but it's not easy.

I use an excel macro to replace parts and assemblies in a model assembly.

My program works well on my PC but I just noticed a problem with the version of the assemblies that the macro will look for on another PC.

Example:

If I extract an assembly on my PC (PC1), modify it and then put it back in the PDM safe (I don't have any more extracts on my PC)

If, on another PC (PC2), I use my Excel macro and import this freshly modified assembly, the version I will recover is the version before modification.

Technically, the way my excel macro will fetch my assembly is very simple, my excel file contains assembly names and their locations and uses this code (below) to replace a model part (PIECE_A _REMPLACER) included in the ASSEMBLAGE_MODELE with the selected assembly (NEW_PART_NAME) which has the path NEW_PART_PATH:

boolstatus = swModel.Extension.SelectByID2(PIECE_A_REMPLACER & "@" & ASSEMBLAGE_MODELE, "COMPONENT", 0, 0, 0, True, 0, Nothing, 0)

boolstatus = swModel.ReplaceComponents2(NEW_PART_PATH & "\" & NEW_PART_NAME, "", False, 0, True)

 

Not understanding why the version of the assembly that the PC2 was opening I closed everything and manually searched (in PDM) for this assembly that I want to import into my model assembly then I opened it, and there .... the correct version opens (the version I had worldified on the PC1).

I close everything and then try my macro again via excel.... It works, it now imports the correct version of the solidworks file.

I first thought it was a problem with the PC2's cash memory and that therefore solidworks was opening what it had in its cash memory and not the latest version of each file.

Except that... on another try, I now try to import an assembly (always replace a part in my model assembly with this new assembly) that did not exist before in the PDM safe: the folder in which this new assembly is is did not exist before (the PC2 never opened the folder before). 

On the PC2, I test my Excel macro and there the program reacts as if it couldn't even find the file in question... he moves on without doing anything.... although, as with the other parts, I give it a correct file name and location.

I redo everything, I look for this new file on the PDM of the PC2, I find it and open it... Everything is going well.

I redo everything and try my Excel macro again... It works, it finally finds the new file.

It would seem that via Excel, even if I give a valid file location, the macro does not have access to the latest version of the PDM vault, not just of a file but of any PDM. 

Is there on each PC a kind of "cash memory of the PDM safe" or something like that?

So I was thinking, at the beginning of to my Excel macro, to add a line to empty this cash memory (if it exists) and therefore force the macro to go and draw from the current version of PDM and not a memorized one....

If you have an idea, or if I went completely in the wrong direction... tell me... maybe it's just in the way I look for my files in my macro...

Thanks in advance

Yves

PS: sorry for the lack of accents, I'm in the UK so QWERTY keyboard

Hello

In your macro you need to get the latest version of the file before processing otherwise it takes the version that is in local cache or nothing if no local version.

Kind regards

1 Like

See: http://help.solidworks.com/2017/english/api/epdmapi/epdm.interop.epdm~epdm.interop.epdm.iedmfile5~getfilecopy.html?verRedirect=1

1 Like

Hello d.roger, 

I admit that I can't find the part of code in the example that I have to insert in my code to have the file version before processing instead of the local cash version.

Is this a trick to add in my code that works with my current code or do I have to totally change my part import method?

Thank you

Yves

Hello

You will find an example of how to get the latest version of a file on the post http://www.lynkoa.com/forum/import-export-formats-neutres/obtention-de-la-derni%C3%A8re-version-dun-fichier-provenant-du-coffre, to be adapted to your needs of course.

Kind regards

From what I understand from your snippet of code, you need to redefine your NEW_PART_PATH and NEW_PART_NAME variables which must correspond to the Folder.LocalPath and File.Name of the example given above.

I haven't tested it but it must look something like this:

...
Dim File As IEdmFile5
Dim Folder As IEdmFolder5
Set File = Vault.GetFileFromPath(NEW_PART_PATH & "\" & NEW_PART_NAME, Folder)
    
boolstatus = swModel.Extension.SelectByID2(PIECE_A_REMPLACER & "@" & ASSEMBLAGE_MODELE, "COMPONENT", 0, 0, 0, True, 0, Nothing, 0)
    
boolstatus = swModel.ReplaceComponents2(Folder.LocalPath & "/" & File.Name, "", False, 0, True)
    
...

 

otherwise another solution would be to include in the macro, the opening and closing of the file in solid in order to force PDM to load the latest version. But the processing time would also be longer....

Otherwise D.roger's solution is the best I think.

Kind regards

Hello 

Thank you for your answers, I think I understood but my problem is that when I test my code it seems that it can't connect to the vault:

Dim Vault As New EdmVault5
Vault.LoginAuto "PDM", 0

 

I took care to activate the PDM library in Excel:

I don't understand...

I also tested with the method:

Vault.Login (USERNAME,PASSWORD,VAULTNAME)

but I arrive at the same result

Did I forget something?

Thanks in advance

Hello

In my opinion, write instead:

Set vault = New EdmVault5 

 

1 Like

First try:

In order to get over this connection problem to the trunk for now I have put a condition:

'Connection to the Vault
If Vault.IsLoggedIn Then
    Vault.LoginAuto "PDM", 0
End If

So I just have to connect to PDM before and then the macro skips this step. 

On the other hand, when the macro arrives at:

Set File = Vault.GetFileFromPath(NEW_PART_PATH & "\" & NEW_PART_NAME, Folder)

I get an error message telling me that I am not connected to the vault... yet the macro passed the connection stage since I was connected...

 

Second Try:

this time I connect to the PDM before launching the macro, which should put me back in the same conditions as before (without the "If Vault.IsLoggedIn Then" condition), so I have the PDM connection window... except that it works...

 

In addition, the connection via macro is independent of the connection via the explorer. For my part, I can run a macro with an admin account while being connected with my normal account on the vault.

Macros call on instances and therefore launch a second session. The only drawback (but I never find myself in this situation) is not trying to do something else at the same time otherwise a guaranteed crash.

As it stands, you have to set everything to parameters via the macro to avoid interacting with a SW or a safe already in operation on the workstation where the operation is launched.

1 Like

 Hello Cyril,

It changes absolutely nothing 

But in both cases I notice that, even if I have the following message from the back:

I'm still connected to PDM afterwards...

 

 

Hello

I'm surprised by the error message, it indicates that your macro can't connect to the IEdmVault18 object while you declare a Vault object in EdmVault5, wouldn't there be a Vault object already declared earlier in your macro?

Kind regards

Unfortunately no, in order I have:

Dim Vault As New EdmVault5

If Vault.IsLoggedIn Then
    Vault.LoginAuto "PDM", 0
End If

I can do a search on "Vault" but I can't find another one before...

In your if you ask to connect if you are already connected!!!!

You have to put :

If Not Vault. IsLoggedIn Then
      Vault. LoginAuto "PDM", 0
End If

Yes I realized this error and I changed to:

If Not Vault.ISLoggedIN Then

but it doesn't work any better....

You are connected to the vault yes but it is not via the macro (if you check only via the vault icon in the notification area it does not tell you if your macro has managed to connect or not, as said above it is independent).

I think it's in your way of declaring vault, I'll try the writing below following a quick search on google:

Dim vault as IEdmVault5 = New EdmVault5
vault.LoginAuto ("PDM",0)

 

He doesn't seem to like this writing:

Here's an example of code that works for me:

Sub Macro1()
    Dim vault As New EdmVault5

    Dim File As IEdmFile5
    Dim Folder As IEdmFolder5

    vault.LoginAuto "Coffre", 0

    Set File = vault.GetFileFromPath("C:\Coffre\TEST\0088880002.SLDPRT", Folder)

    MsgBox Folder.LocalPath & "\" & File.Name
End Sub

 

With the following libraries:

Maybe already do a test with only the connection in another macro.

Kind regards

1 Like