Find a solidworks files in EPDM and

I am trying to create a macro the finds solidworks files in EPDM but I am stuck on understanding how to make it.

I am trying to write a macro that goes into EPDM finds a file name that matches one on an excel bom and adds it to an assembly.

all i have for this macro is

Sub Search_EPDM()

Dim SWapp           As SldWorks.SldWorks

Dim VaultApp        As EdmVault5

Dim Vault           As IEdmVault14

Dim File            As IEdmFile5

Dim EPDMSearch      As IEdmSearch7

Dim EPDMSearchR     As IEdmSearchResult5

Set Vault = New EdmVault5

'Vault.GetLoggedInWindowsUserID ("MO-Test")

EPDMSearch = Vault.CreateSearch()

EPDMSearchR = EPDMSearch.GetFirstResult

End Sub

I cant figure out how to add the criteria to search or if i can use any of my excising macro for adding components into an assembly

I am also trying to pull information from the file like size and type

SolidworksApi macros
Answers 4
MD
MD 2016-02-19 Best Answer

Set the properties on your EPDMSearch object before you call GetFirstResult. For example:

EPDMSearch.StartFolderID = 1

EPDMSearch.FileName = "%.sld%"

You'll have to use the SolidWorks API to add components.

The search result object has a FileSize property.

JP
JP 2016-02-19

I has taken me most of the day an the search seems to be really sloppy but i finally just got it to work. when i add your definitions in the EPDMSearch.StartFolderID = 1 dosent seem to affect the way it searches and when i use the

EPDMSearch.FileName = "%.sld%" it causes my code to not work. could you give me some info on what they do so i can inprove my search ability.

'Replaces Module 3

Sub Search_EPDM()

Dim SWapp           As SldWorks.SldWorks

Dim SWAddComp       As SldWorks.ModelDoc2

Dim VaultApp        As New EdmVault5

Dim File            As IEdmFile5

Dim EPDMSearch      As IEdmSearch7

Dim EPDMSearchR     As IEdmSearchResult5

Dim EPDMSearchR2    As IEdmSearchResult5

Dim obj             As Object

Dim PFile           As String

Dim Count           As Long

Dim Errors          As Long

Dim Warnings        As Long

Dim CompType        As Long

Set SWapp = CreateObject("SldWorks.Application")

VaultApp.Login "Username", "Password", "VaultName"

Set EPDMSearch = VaultApp.CreateSearch()

'EPDMSearch.StartFolderID = 1

'EPDMSearch.FileName = "%.SLD%"

Set EPDMSearchR = EPDMSearch.GetFirstResult

PFile = EPDMSearchR.Path

Debug.Print PFile

While Right(PFile, 6) <> "SLDPRT"

PFile = EPDMSearch.GetNextResult.Path

Sheets("Sheet1").Range("A1").Offset(Count, 0).Value = PFile

Sheets("Sheet1").Range("B1").Offset(Count, 0).Value = Right(PFile, 6)

Count = Count + 1

Wend

If Right(PFile, 6) = "SLDPRT" Or Right(PFile, 6) = "sldprt" Then

CompType = 1

Else

CompType = 2

End If

Set SWAddComp = SWapp.OpenDoc6(PFile, CompType, 1, "", Errors, Warnings)

SWAddComp.Visible = True

End Sub

MD
MD 2016-02-19

Your root folder in the vault is has the ID of 1 so this is searching from there. Forgot this EDMSearch.Recursive = True (this will look in subfolders). If you want to start searching in a different folder then you will have to create an object for it.

Dim searchFolder as IEdmFolder5

searchFolder = VaultApp.GetFolderFromPath("C:\vault\subfolder\etc")

EPDMseach.StartFolderID = searchFolder.ID

JP
JP 2016-02-22

This is the code i am using to search is looks for solidworks parts or assemblys and matches them to the component name.

'Login to EPDM Vault

   VaultApp.Login "Username", "Password", "VaultName"

   

'Create a search in the EPDM Vault

    Set EPDMSearch = VaultApp.CreateSearch()

'Get the first file in the EPDM Vault

    Set EPDMSearchR = EPDMSearch.GetFirstResult

'Get the File info from EPDM Vault File

    FPath = EPDMSearchR.Path

    FName = EPDMSearchR.Name

    FType = EPDMSearchR.ObjectType

    FDate = EPDMSearchR.FileDate

While Mid(FName, 1, Len(FName) - 7) <> CompName Or Right(FName, 6) = "SLDDRW" Or _

Right(FName, 6) = "slddrw"

On Error GoTo End_of_Sub

    Set EPDMSearchR = EPDMSearch.GetNextResult

    FName = EPDMSearchR.Name

Wend

'Define file info variables

FPath = EPDMSearchR.Path

FName = EPDMSearchR.Name

FType = EPDMSearchR.ObjectType

FDate = EPDMSearchR.FileDate

FSize = EPDMSearchR.FileSize