PDMWorks Macro times out at connection.documents

I am trying to use a macro to retreive and save a file from PDMWorks.  We're using SolidWorks 2016, I am stepping through the VB code and the vault connection works fine, but once I get to connection.Documents it freezes and eventually times out.  Here's what I've got right now:

Sub main()

Dim connection As PDMWConnection

Set connection = CreateObject("PDMWorks.PDMWConnection")

connection.Login "username", "admin", "localhost"

Dim alldocs As PDMWDocuments

Dim doc As PDMWDocument

Set alldocs = connection.Documents

Set doc = connection.GetSpecificDocument ("102-056-01.SLDPRT")

doc.Save "E:\\VaultFile\\"

connection.Logout

I have tried to simplify the code as much as possible for now to try to identify the issue.  The underlined line is as far as I get when stepping through the code.  I would appreciate any thoughts or suggestions.  I've tried from multiple machines, always with the same results.

SolidworksApi macros
Answers 8
ST
ST 2017-10-20

One way to simplify your code even further would be to take out the allDocs line completely.

Since you're calling GetSpecificDocument on the next line, there is no reason to want to get all the documents anyway.

MM
MM 2017-10-20

First off, on the line in question, you should be passing an argument. Either a specific project or and empty string. Try:

Set alldocs = connection.Documents("")

However using this method is very time consuming because the program has to grab every document in the vault. If all you are looking to do is get a specific document or documents the method Simon suggested is way faster.

TM
TM 2017-10-20

I will give that a try.  The end goal is to extract all the files, I just thought I'd start simple and test out the example codes first then build up to it.  I've found several examples in both the SolidWorks API and in the forums and none of them use the ("") after that line but if that's the missing link I'll be happy to use it

Thank you.

TM
TM 2017-10-20

It would appear that my vault just might be too big to parse through in a timely manner, so if I do it with a project listed in that argument it works fine, but I cannot leave the argument empty or open.

MM
MM 2017-10-20

I had a feeling that was the issue. Good luck.

TW
TW 2017-10-23

Hey Tounine,

Try using a search from the API instead and iterate through the results, it will be super fast...er!

You'll need to add a reference to EPDM.Interop.epdm.dll to your project

Here's the code to handle the search, I'll let you figure out the code for what to do with the object once you find it.

<p>    Private Sub FindFiles(ByRef vault As IEdmVault5)</p><p>        On Error GoTo ErrHand</p><p></p><p></p><p>        Dim search As IEdmSearch5</p><p>        search = vault.CreateSearch</p><p></p><p></p><p>        'search.AddVariable("Document Number", "102-056-01") '<---Add a datacard variable name to search for here</p><p>        'search.State = "Released" '<--- Use this as a search for the state you want to search in</p><p>        search.FileName = "102-056-01.SLDPRT" '<---Apply a file type filter to search for (i.e. your filename or "%.sldprt")</p><p>        search.FindFolders = False 'Do not return folders in the search</p><p></p><p></p><p></p><p></p><p>        Dim message As String</p><p>        message = "These are the files the search found:" + vbLf</p><p></p><p></p><p>        Dim result As IEdmSearchResult5</p><p>        Dim folder As IEdmFolder5</p><p>        result = search.GetFirstResult</p><p>        message = ""</p><p></p><p></p><p>        While Not result Is Nothing</p><p>            GetLatestVersion(result.Name, vault.GetFolderFromPath(GetFolderFromFileName(result.Path)), vault)</p><p>            message = message & "PDM search found file " & result.Path & "\" & result.Name + vbLf</p><p>            result = search.GetNextResult</p><p>        End While</p><p></p><p></p><p>        MsgBox(message)</p><p>        Exit Sub</p><p></p><p></p><p>ErrHand:</p><p>        Dim ename As String</p><p>        Dim edesc As String</p><p>        vault.GetErrorString(Err.Number, ename, edesc)</p><p>        MsgBox(ename + vbLf + edesc)</p><p>    End Sub</p>

Hope this helps!

Tim CEPA

Believe in The Q!​

comment imagecomment imagecomment imagecomment image
ST
ST 2017-10-24

Note that the original question was regarding Workgroup PDM.

TW
TW 2017-10-24

Thanks for the insight Simon but it actually does not clarify that. The OP posted in API/Macros and mentioned PDMWorks, which could be either PDMWorks Workgroup or PDMWorks Enterprise as those were once both product names. My mistake for not being familiar with Workgroup API but I did offer help in good faith.

Besides, everyone on this thread got a nice tutorial on the SOLIDWORKS PDM Pro API!

Hopefully it will help someone!

Tim CEPA

Believe in The Q!