7 Replies Latest reply on Jul 20, 2015 5:28 AM by Deepak Gupta

    Macro to know if a file exist in Vault ?

    Mofel Mofel



      It's my first post on the forum; We are using SW2014 with WPDM.


      Few month ago, i modified a macro found on the forum to export all drawings existing in the vault in PDF and put it a network folder.

      This works well.


      Today i'm trying to add that for each draw i need to export a STEP of the relative 3D part or a step of the relative 3D Assembly.


      What i wanted to do is:

      --> For each draw

      --> Find the name part of the part or the name of the assembly

      --> get the .sldprt file or .sldasm file from the vault

      --> export it in STEP

      --> delete the local source file.


      My problem is on the frist step:

      --> Is there any function in the API to be able to know the name of a part or assembly referenced in a sldrw file ?


      Thanks for your help !

          • Re: Macro to know if a file exist in Vault ?
            Mofel Mofel

            Thanks Gupta for your reply but this is for an open draw.


            My macro is a batch so i don't have any draw open and any view selected.


            You don't have any example corresponding more to i need to do ?




              • Re: Macro to know if a file exist in Vault ?
                Deepak Gupta

                Don't have a macro but I remember making a batch macro to save referenced model (though all files were on local hard disk and not vault)

                  • Re: Macro to know if a file exist in Vault ?
                    Mofel Mofel

                    Thanks again for your help; i tried all day long and didn't manage to make it through the vault.

                    Another solution to solve my problem would be to "guess" the part or the assembly name which in 98% of the case is the same than the draw (the 2% can be done manually for now).


                    I works well but:


                    I use this to get the part or the assembly in local:


                        Set doc = alldocs(fileprt)

                        doc.Save "C:\temp dir\"


                    It works well; i get the assembly and the prt and after save it in .step with another Sub in the macro.


                    The problem is as i need to guess the file name and don't know if it is a .sldprt or .sldasm when i have an error the script kill.


                    How in VBA, can i catch the error and try another name of file ?


                    Thanks for your help !


                      • Re: Macro to know if a file exist in Vault ?
                        Deepak Gupta

                        File extension or model type can be found. Are the files in the vault when you run the macro. If yes then I feel you would have to check then out, activate the model and then save as step file. And finally delete all local files

                          • Re: Macro to know if a file exist in Vault ?
                            Mofel Mofel

                            Thanks Deepak for your advises.


                            i finally made a function that return the first part found in the draw (we could return an array but i don't need it)


                            As i'm a beginner in VBA i'm pretty sure that there is few things to optimize. Do not hesitate to let me know !


                            ' the function don't check that the file exist... you should check it before or add it in the function.

                            Function GetFilePartFromDraw(sDocFileName As String)


                                Dim swApp               As SldWorks.SldWorks


                                Dim swModel             As SldWorks.ModelDoc


                                Dim nDocType            As Long


                                Dim nErrors             As Long


                                Dim nWarnings           As Long



                                Set swApp = CreateObject("SldWorks.Application")


                                Dim swSelMgr                    As SldWorks.SelectionMgr



                                Dim swDrawModel                 As SldWorks.ModelDoc2


                                Dim swDraw                  As SldWorks.DrawingDoc


                                Dim swSheet                 As SldWorks.Sheet


                                Dim swView                  As SldWorks.View


                                Dim swActiveView            As SldWorks.View


                                Dim bRet                    As Boolean



                                ' Determine type of SolidWorks file based on file extension


                                If InStr(LCase(sDocFileName), "slddrw") > 0 Then


                                    nDocType = swDocDRAWING



                                    Exit Function


                                End If



                                Set swModel = swApp.OpenDoc6(sDocFileName, nDocType, _

                                swOpenDocOptions_Silent, "", nErrors, nWarnings)



                                Set swDraw = swModel


                                Set swSheet = swDraw.GetCurrentSheet


                                Set swActiveView = swDraw.ActiveDrawingView


                                Set swView = swDraw.GetFirstView


                                While Not swView Is Nothing


                                    If swView.GetReferencedModelName <> "" Then

                                        GetFilePartFromDraw = swView.GetReferencedModelName

                                        swApp.CloseDoc (sDocFileName)

                                        Exit Function


                                    End If


                                    bRet = swDraw.ActivateView(swView.GetName2):


                                    If False = bRet Then

                                        bRet = swDraw.ActivateSheet(swView.GetName2)


                                    End If


                                    Set swView = swView.GetNextView



                                swApp.CloseDoc (sDocFileName)


                            End Function