AnsweredAssumed Answered

EPDM API issues pulling parts for SolidWorks

Question asked by Joe Pickens on Mar 9, 2016
Latest reply on Mar 10, 2016 by Joe Pickens

So I wrote a macro that searches the vault and finds the files and then i use the file locations to insert the files into solidworks. the macro used to work fine but i made a change to do a batch add into the solidworks assembly and now it acts like the API cant reach the file locations and also when i switch it back the macro still acts like it cant find the file locations.

 

This is the macro I wrote

 

Sub Open_New_Asm_and_Srt_Search()

 

'For Solidworks

Dim SWApp           As SldWorks.SldWorks

Dim SWModel         As SldWorks.modelDoc2

Dim SWAsm           As SldWorks.assemblyDoc

Dim SWAddComp       As SldWorks.modelDoc2

Dim SWComp          As Component2

Dim SWAsmEvents     As Class1

 

'For EPDM

Dim VaultApp        As New EdmVault5

Dim EPDMSearch      As IEdmSearch7

Dim EPDMSearchR     As IEdmSearchResult5

Dim EPDMFile        As IEdmFile10

 

'General

'Dim SWCompName      As String

Dim TLAsmTemp       As String

Dim SWAsmTitle      As String

Dim SWAsmName       As String

Dim SWCompName      As String

Dim FName           As String

Dim CompName        As String

Dim CompPath(200)      As String

Dim FPath           As String

Dim FType           As String

Dim FDate           As String

Dim VaultID         As String

Dim UserID          As String

Dim Passowrd        As String

Dim OpSeq           As String

Dim count           As Integer

Dim Row             As Integer

Dim i               As Integer

Dim FSize           As Long

Dim Errors          As Long

Dim Warnings        As Long

Dim PrtAsm          As Long

Dim Str             As Variant

Dim CompsForm       As Variant

Dim Comps           As Variant

Dim AddComps        As Variant

Dim boolstat        As Boolean

 

Dim CompCoordSysNames(1) As String

Dim CompXforms(15)              As String

Dim VCompCoordSysNames As Variant

Dim VCompXforms          As Variant

 

'Open new session of SolidWorks

    Set SWApp = CreateObject("SldWorks.Application")

 

'Define assembly template location

    TLAsmTemp = "C:\Users\pickensj\Documents\Templets\JOE'S MO ASSY.asmdot"

 

'Open new Solidworks Assembly with specified Template

    Set SWModel = SWApp.NewDocument(TLAsmTemp, 0, 0, 0)

 

'Show Solidworks assembly

    SWModel.Visible = True

 

'Set up events

    Set SWAsm = SWModel

 

'Get the title of the assembly document

    SWAsmTitle = SWModel.GetTitle

           

'Split the title into two strings using the period(.) as the delimiter

    Str = Split(SWAsmTitle, ".")

 

'Set assemby name for use in mating in module5

    SWAsmName = Str(0)

 

'Login to EPDM Vault

    VaultApp.LoginAuto "MIG1", 0

               

'Do a loop search till there is a blank value in column A

    While Sheets("JDE BOM").Range("A6").Offset(i, 0).Value <> ""

 

    'Use Values that only have the number 1 in column E

        If Sheets("JDE BOM").Range("E6").Offset(i, 0).Value = 1 Then

       

        'If the statement is true use the value in column "A" as the name of the file

            CompName = Sheets("JDE BOM").Range("A6").Offset(i, 0).Value

            OpSeq = Sheets("JDE BOM").Range("C6").Offset(i, 0).Value

                   

        'Create a search in the EPDM Vault

            Set EPDMSearch = VaultApp.CreateSearch()

            EPDMSearch.FileName = "%" & CompName & "%"

            EPDMSearch.FindFiles = True

            EPDMSearch.FindFolders = False

            EPDMSearch.FindHistoricStates = False

            EPDMSearch.Recursive = True

       

        'Get the first file in the EPDM Vault

            Set EPDMSearchR = EPDMSearch.GetFirstResult

 

        If EPDMSearchR Is Nothing Then

            GoTo End_of_Sub

        End If

        'Get the File info from EPDM Vault File

            FPath = EPDMSearchR.Path

            FName = EPDMSearchR.Name

            FDate = EPDMSearchR.FileDate

 

        'Loop through all files in the vault untill...

            While Right(FName, 6) = "SLDPRT" And Right(FName, 6) = "sldprt" And _

                Right(FName, 6) = "SLDASM" And Right(FName, 6) = "sldasm"

 

            'If there is no matching file in the vault end sub

                On Error GoTo End_of_Sub

            'Goto next file

                Set EPDMSearchR = EPDMSearch.GetNextResult

                FName = EPDMSearchR.Name

               

            Wend

        'End of loop

 

        'Define file info variables

            CompPath(count) = EPDMSearchR.Path

           

        'Set variable incrament instance

            count = count + 1

 

        End If

 

End_of_Sub:

 

    'Set variable incrament instance

        i = i + 1

 

    Wend

 

' Add a rotational diagonal unit matrix (zero rotation) to the transformation matrix

    CompXforms(0) = 1#

    CompXforms(1) = 0#

    CompXforms(2) = 0#

    CompXforms(3) = 0#

    CompXforms(4) = 1#

    CompXforms(5) = 0#

    CompXforms(6) = 0#

    CompXforms(7) = 0#

    CompXforms(8) = 1#

 

' Add a translation vector to the transformation matrix

    CompXforms(9) = 0#

    CompXforms(10) = 0#

    CompXforms(11) = 0#

 

' Add a scaling factor to the transform

    CompXforms(12) = 1#

 

' The last three elements of the transformation matrix are unused

 

' Register the component's coordinate system name

    CompCoordSysNames(0) = "Coordinate System1"

 

  ' Add the component to the assembly.

  VCompXforms = CompXforms

  'vcompXforms = Nothing  ' also achieves zero rotation and translation of component

  VCompCoordSysNames = CompCoordSysNames

 

Comps = CompPath

 

'Acts like file path is invalid/ works when i set path instance to normal folder and doesn't when pointed to files in the vault

AddComps = SWAsm.AddComponents3(Comps, CompXforms, VCompCoordSysNames)

 

End Sub

Outcomes