6 Replies Latest reply on Sep 27, 2018 2:06 AM by Sascha Smolny

    BatchGet - successfully completed?

    Sascha Smolny

      Hello,

       

      I'm going to write a macro to get the files of an assembly in the version as created. I use EdmUtil_BatchGet for this.

       

      It works pretty well, but i have no idea how to check if all files have been copied successfully. If i have one file locked by an SolidWorks session this File can not be copied but i do not get an error message.

      My Code:

       

                  Dim batchGetter As IEdmBatchGet

                  batchGetter = vault.CreateUtility(EdmUtility.EdmUtil_BatchGet)

                  Dim aFile As IEdmFile5 = vault.GetFileFromPath("C:\PDM\BG\bg 00414.SLDASM")

                  Dim Item As New EdmSelItem

                  Item.mlDocID = aFile.ID

                  Dim aPos As IEdmPos5 = aFile.GetFirstFolderPosition

                  Item.mlProjID = aFile.GetNextFolder(aPos).ID

                  Dim Items(0) As EdmSelItem

                  Items(0) = Item

                  batchGetter.AddSelection(vault, Items)

                  batchGetter.CreateTree(Me.Handle, 1) 'http://help.solidworks.com/2015/English/api/epdmapi/EPDM.Interop.epdm~EPDM.Interop.epdm.EdmGetCmdFlags.html

                     'I dont want to show the Dialog

                  'batchGetter.ShowDlg(Me.Handle)

                   batchGetter.GetFiles(Me.Handle, Nothing)

       

      The GetFiles method is a void method. But on the API-Help Page are returns specified:

      Return codes:

      • S_OK: The method successfully executed.
      • S_FALSE: One of the arguments is invalid.

       

      How to use these? Or how can i test if all files where successfully transferred?

       

      Regards

      Sascha

        • Re: BatchGet - successfully completed?
          Jim Sculley

          You use GetFileList to determine the status of the various files that were part of the Get operation, passing in the appropriate EdmGetFileListFlag enumerarion value:

           

          EdmSelectionList5 selList = batchGet.GetFileList((int)EdmGetFileListFlag.Egflf_GetRetrieved); //Files successfully retrieved
          //Process files here
          selList = batchGet.GetFileList((int)(EdmGetFileListFlag.Egflf_GetFailed | EdmGetFileListFlag.Egflf_GetUnprocessed)); //Files that failed or were not processed
          //Process files here
          
            • Re: BatchGet - successfully completed?
              Sascha Smolny

              Hello,

               

              many thanks for your Answer. But I can not handle that...

              If i use the ShowDlg and check all files i get "EdmGetFileListFlag.Egflf_GetRetrieved" with all the files. And no errors.

              If i only let the selection as is i get:

              Egflf_GetFailed              7

              Egflf_GetLocked            0

              Egflf_GetRetrieved        1

              Egflf_GetUnprocessed   22

              In the Dialog are:

              3 Drawing Files selected  (without warnings)

              7 Files had warnings

              22 not checked

               

              If i get the FileListFlags before i use the GetFiles method i get the same result. So i think i had to check every time all files  to check if all are ok?

              Regards

              Sascha

            • Re: BatchGet - successfully completed?
              Sascha Smolny

              Hello,

               

              thanks Tim for the Tip but converting code from C# is no problem for me.

               

              Here is a screenshot of the Dialog (Sorry...in German language):

              dialog.PNG

               

              I did not open the Files in SolidWorks. So i cant make a screenshot of the TaskPane Tree.

               

              My current idea (if the other will not work):

              Get the fileList and check manually the versions. (Unfortunately, I am not ready yet)

              fileList = batchGetter.GetFileList(EdmGetFileListFlag.Egflf_GetLocked & EdmGetFileListFlag.Egflf_GetFailed & EdmGetFileListFlag.Egflf_GetRetrieved & EdmGetFileListFlag.Egflf_GetUnprocessed)

              Dim poSel As EdmSelectionObject

              aPos = fileList.GetHeadPosition()

              poSel = Nothing

              While Not (aPos.IsNull())

                              fileList.GetNext2(aPos, poSel)

                              If poSel.mlGetVersion <> poSel.mlLocalVersion Then

                                  'MsgBox(poSel.mbsPath)

                              End If

              End While

               

              So i get only one Drawing that is not in the right verison...

               

              Regards

              Sascha

              • Re: BatchGet - successfully completed?
                Sascha Smolny

                Hello,

                i have found a option to get a message if the operation is not successful.

                First i have created the Class EdmGetOpCallback

                Class EdmGetOpCallback
                        Implements IEdmGetOpCallback
                        Public Property HasErrors As Boolean = False
                
                        Public Sub LogMessage(eMsgID As EdmGetOpMsg, hCode As Integer, bsDetails As String) Implements IEdmGetOpCallback.LogMessage
                            'Throw New NotImplementedException()
                        End Sub
                
                        Public Sub ProgressBegin(eType As EdmProgressType, lSteps As Integer) Implements IEdmGetOpCallback.ProgressBegin
                            'Throw New NotImplementedException()
                        End Sub
                
                        Public Sub ProgressEnd(eType As EdmProgressType) Implements IEdmGetOpCallback.ProgressEnd
                            'Throw New NotImplementedException()
                        End Sub
                
                        Public Function ConfirmReplace(eReason As EdmGetConfirmReason, bsPath As String) As Boolean Implements IEdmGetOpCallback.ConfirmReplace
                            'Throw New NotImplementedException()
                            Return False
                        End Function
                
                        Public Function ProgressStep(eType As EdmProgressType, bsMessage As String, lProgressPos As Integer) As Boolean Implements IEdmGetOpCallback.ProgressStep
                            'Throw New NotImplementedException()
                            Return True
                        End Function
                
                        Public Function ReportFailure(lFileID As Integer, bsPath As String, hError As Integer, bsDetails As String) As Boolean Implements IEdmGetOpCallback.ReportFailure
                            'Throw New NotImplementedException()
                            HasErrors = True
                            Return False 'False = nicht weiter machen!
                        End Function
                    End Class
                

                 

                I have only added

                Public Property HasErrors As Boolean = False
                

                and in the ReportFailure Function:

                HasErrors = True
                Return False
                

                Return False is to abort the operation on errors.

                So can i use it:

                Dim CB As New EdmGetOpCallback
                batchGetter.GetFiles(Me.Handle, CB)
                 If CB.HasErrors = True Then
                     MsgBox("Error found!")
                End If
                

                 

                If a File is locked I get the Error: "Operation wurde vom Benutzer abgebrochen." (Operation canceled by user). No clue why...but it seems to work (i want only get a error if something unexpected happened.

                See edit! If a File is locked i get the right Error Message!

                 

                I hope that this works as desired.

                 

                My other Idea will not work:

                fileList = batchGetter.GetFileList(EdmGetFileListFlag.Egflf_GetLocked & EdmGetFileListFlag.Egflf_GetFailed & EdmGetFileListFlag.Egflf_GetRetrieved & EdmGetFileListFlag.Egflf_GetUnprocessed)
                

                Gives me not all Files. If a File is locked the File is not in the fileList. So i can not check it.

                [edit] If i use  "batchGetter.FileCount" i get more Files (in my example 25) as the fileList count (22 Files). So 3 Files are not ok. It seems that drawings from contained Assemblys not be fetched. But they are displayed in the dialog (???). [/edit]

                Is there a possibility to get the Files that have a "Stop" reason? (Locked by another user, open in other application...)

                 

                Regards

                Sascha

                 

                [EDIT]

                I have found that no data has been copied if i use the EdmGetOpCallback

                It is very important to return true in ProgressStep function:

                 

                  Public Function ProgressStep(eType As EdmProgressType, bsMessage As String, lProgressPos As Integer) As Boolean Implements IEdmGetOpCallback.ProgressStep
                            'Throw New NotImplementedException()
                            Return True
                        End Function
                

                 

                Than it worked as expected.

                [/Edit]

                 

                n = SoFals