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
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.
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
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.
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.
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.
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
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.
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.
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.
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.
I don't see it. For your information, I don't have any operating error with the following macro:
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
The only message I get is that the Epdm asks me if I want to extract the file when it is loaded, a normal message since it is not. FYI I don't need the GetFileCopy line.