Vba - EPDM Link

Hi all

I have a problem opening my EDPM files via my macro. In my current project, I had to create a macro in order to open my files being stored in the EPDM vault or when I launch my macro, working very well when the parts are on my desktop the macro goes into Debug:

When running the macro, the files are not extracted from EPDM and this is a desire to have it read-only only. I have this problem on my workstation with my EPDM session, with my session on another workstation and on another workstation with another session so nothing to do with the psote or the session.

But I discovered something: When I open EPDM in Windows Explorer and I click on my part (no double click just click to have it in the preview) I have a window that opens:

And following this loading, not lasting 3 hours as indicated, my macro works wonderfully.

So I was wondering if anyone knew where this came from and maybe fix a problem in the autoload?

One last point, I need, for my macro to work, to click Only on 3D files, drawings are not a problem for me.

Good afternoon

 


capture_error.png

Hello

In your macro you have to start by connecting to your vault and then get the latest version of your file before opening it, I don't know how it's written in VBA but here is an example in C#:

vault1 = new EdmVault5();

if (!vault1. IsLoggedIn)
{
      vault1. LoginAuto("Your safe", this. Handle.ToInt32());
}

IEdmFile5 file3D = default(IEdmFile5);

IEdmFolder5 folderBOM = null;

file3D = vault1. GetFileFromPath("Your File", out folderBOM);

file3D.GetFileCopy(this. Handle.ToInt32(), "");

Kind regards

1 Like

 Hello d.roger,

Thank you very much for your answer because it reassures me to know that there is a solution!
On the other hand, I'm starting to have some knowledge of Vba but nothing more and I don't know anything about C# language so I'll wait for other answers to know how to follow in Vba.

In EPDM with Windows Explorer,

the fact of having as a setting "miniature SW 3D"

that the last tab used in EPDM is "Preview"

and select a new file,

This automatically makes a "get" on the file (if there is no cached version on the PC)

 

then if we already have a version in "cache" without being the last one,

there is no "auto get" with the "Forecast" tab

But this behavior can be changed depending on the user/group settings.

(like letting the user manage cached versions, or forcing the latest version, etc...)

1 Like

Hello

I believe this is a limitation of the SW API in VBA. Because if you look in the help for no documentation in VBA: http://help.solidworks.com/SearchEx.aspx?q=EdmVault5&sort=&version=2017&lang=english&prod=api

1 Like

Hello, if the APIs exist in .net, I think they also exist in vba.

To help you out, you can copy the code you've been given into a C# VB.net converter. You can find several of them on the internet. Since Vba is taken from vb.net, the code will be close enough for you to understand.

From memory, there is a dll to load to access the pdm objects.

Kind regards.

1 Like

Yves.T :

No need for a converter, there are many examples in vb.net. Here are several links: http://help.solidworks.com/2017/english/api/epdmapi/Traverse_Folders_and_Files_in_Vault_Example_VBNET.htm

1 Like

Hello

There is indeed a DLL to load, it's "EPDM. Interop.epdm.dll" that is located in the SOLIDWORKS Enterprise PDM installation directory.

Kind regards

1 Like

Hello again,

You can try in a new macro with the following lines:

     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 "Le_nom_de_ton_coffre-strong", 0

         Set File = Vault.GetFileFromPath("Le_nom_de_ton_fichier_avec_le_chemin", Folder)
    
         Set Part = swApp.OpenDoc6("Le_nom_de_ton_fichier_avec_le_chemin", 1, 0, "", longstatus, longwarnings)

     End Sub

Don't forget to change the vault name and file name.

Kind regards

1 Like

Hi all

Being on 2 projects simultaneously I have not yet been able to carry out tests but I should be able to today on the other hand I have some questions following your answers:

- For the ddl loaded, I don't know how to do it... Is it a file to download? A file to link only to my parts?
- In the codes I was able to go through like d.roger  's I noticed that there was a LoginAuto function, how does it work? Because I have to connect to EPDM through this window:

Will this feature conflict with my usual login method? Maybe I'm misinterpreting the term "Auto".

Because ideally I would like that when launching the macro there is a connection check to EPDM (thanks to the window above) and if so then load the documents in the cache when necessary.

But before I get into the code, wouldn't it be easier to modify the EPDM settings like "Clear cache on logout"  or other like in the attachment.

Thank you for your great help


para_epdm.png

Hello

For the connection, it won't conflict. LoginAuto uses local connection parameters so if login/mdp is requested at login, the window will be presented.

When it comes to clearing the cache when you log out, you really have to weigh the pros and cons. This has an impact on the extracted files (the assemblies especially if my memory is correct) and can generate the loss of work. It all depends on your archiving rules and the rigor of your users.

For the rest, there are indeed no more examples in vba (on the 2009 there were) but from VB.NET you can find your way around. However, there will still be features reserved for C# and VB.NET.

 

2 Likes

Hello

For the DLL to be loaded, this is necessary for programs in C#. In VBA you just have to reference "PDMWorks Enterprise 20xx Type Library" in your macro, see the attached image.

For the login window, see Cyril.f's answer above.

Otherwise, I think it's more interesting to start learning a language like VB.net or C# which allow you to do a lot more things either in the form of macros or in the form of independent programs that allow you to easily control EPDM and/or SolidWorks, but that's just a personal opinion. There are excellent courses for learning these languages on different sites such as https://openclassrooms.com/courses/apprenez-a-developper-en-c

Kind regards


references.png
2 Likes

I think it will be useful to you. Moreover, it is very interesting.

The VB.net is more similar to the VBA. Learning will be easier.

Personally I use the EDi Visual Studio in Community version: https://www.visualstudio.com/fr/thank-you-downloading-visual-studio/?sku=Community&rel=15

I also recommend the excellent developpez.com:

The .net forum

.net Courses

The .net FAQ

The Visual Studio section

 

To the right:

How do you run C or VB.net code as macros in SW?

 

 

 

2 Likes

For this project, I'm going to try to be satisfied with the Vba because I'm on an internship and unfortunately I won't be hired and the people who will use my program barely have the basics of Vba...

But for future applications, I will dwell on it more. On the other hand I have a very stupid question, how is it better than the Vba? More possibility? Are they also programs to be coded in a specific module of a software or is it independent? (Just small questions to get an idea before I start learning)

The Vb.net is indeed much more similar to VBA and therefore easier to learn, C# is much less "wordy", it's a matter of taste.

For macros in C# or VB.net in SW, I create DLLs and when I insert new buttons in SW I use these DLLs, see attached image. I ended up making a DLL that is only used to read a text file in which I put the path of my main executable and then to launch this executable, it allows me to have much more flexibility on my programs.

For my programs, I use the open source SharpDevelop IDE.

Kind regards


capture-2.png
1 Like

How is it better than the Vba? More possibility? : Visual Basic for Applications (VBA) is an implementation of Microsoft Visual Basic, VB.NET or C# are programming languages in their own right. MUCH more possibilities.

Are they also programs to be coded in a specific module of a software or is it independent? Independent programming (creating executables), using an IDE such as Visual Studio Community or Sharpdevelop makes things a lot easier.

2 Likes

Indeed it looks more interesting! So it's decided after my project, I'm moving on to learning VB.net.

But regarding my problem I tried the macro of d.roger and the beginning seems to work because when I click on a choice, I have the EPDM connection window that opens.

But the following line doesn't seem to do its job, unless it doesn't fix my problem:

'Active la seconde ComboBox lorsqu'un type est sélectionné dans la 1er liste
 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 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 "Nom_coffre", 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("Chemin + nom de fichier", Folder)
    Set Part = swApp.OpenDoc6("Chemin + nom de fichier", 1, 0, "", longstatus, longwarnings)
    swApp.ActivateDoc2 "Nom fichier", 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...........................
                
             

Here's some of my code and the "object not set"  error appears on the part family recovery line.

Thank you for your help.

Set swDesignTable = swModel.GetDesignTable without the ()?

and dim swDesignTable as SldWorks.DesignTable

In the line:

Vault.LoginAuto "Nom_coffre", 0

You didn't put the name of your safe, I doubt it's called Nom_coffre.

Same in the lines:

Set File = Vault.GetFileFromPath("Path + Filename", Folder)
Set Part = swApp.OpenDoc6("Path + filename", 1, 0, "", longstatus, longwarnings)

or Path + filename should be the name of your file with its path so in the form "C:\Vault-BE\TEST\TestFile.sldprt" for example

Kind regards

Yes yes d.roger don't worry I changed it ^^. I just removed the names to put on the forum ;).

Cyril.f I tried but it still doesn't work.

Edit: I think it has an impact but when I run my File, Part and swDesigntable = Nothing varaibles step by step but I don't see the problem it works if I load the previous version manually.