9 Replies Latest reply on Nov 12, 2017 8:38 PM by Koji Eguchi

    Bug in IModelDocExtension.SaveAs method

    Koji Eguchi

      I am creating a 3D PDF using the IModelDocExtension.SaveAs method.

      If you operate as follows, it is in trouble that results different from the expected result are returned.

      1. Open the drawing file.
      2. Save the drawing file as fileneme.PDF in the IModelDocExtension.SaveAs method.
      3. Close the drawing file.
      4. Start up Acrobat Reader DC and open filename.PDF.
      5. Open part file with SOLIDWORKS.
      6. Save the part file as fileneme.PDF in the IModelDocExtension.SaveAs method.

      When the sixth operation is performed in the above procedure, since filename.PDF is opened in Acrobat Reader DC, it can not be overwritten with exclusive control.

      However, the Return Value of SaveAs method is True (success), Errors and Warnings are both 0.

       

      If filename.PDF was opened by another application, the return value of the method must be False.

      Is this a bug?

       

      SOLIDWORKS version is 2016 SP 5.0.

        • Re: Bug in IModelDocExtension.SaveAs method
          Manikandan Babu

          Hi Koji,

           

          Yes I have checked,it seems to be bug.

           

          Thanks

          Manikandan

          • Re: Bug in IModelDocExtension.SaveAs method
            Deepak Gupta

            Are both file in same folder/location? If not them you may not get any errors.

            • Re: Bug in IModelDocExtension.SaveAs method
              Matt Bieringer

              I think you are correct on this being a bug. That being said, here is a sample code to close the open window of acrobat with a set name. It will only close the window with the specific file name, so if you have multiple abode acrobat windows open it wont close them all. Just replace the "Test.pdf - Adobe Acrobat" with filename & ".pdf - Adobe Acrobat (Or whatever pdf viewer you use)"

               

              Option Explicit
              Private Declare PtrSafe Function PostMessage Lib "user32" Alias "PostMessageA" _
              (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
              lParam As Any) As Long
              Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" _
              (ByVal lpClassname As String, ByVal lpWindowName As String) As Long
              Private Const WM_CLOSE = &H10
              
              Sub CloseWindow()
              Dim Hwnd As Long
              'Find the window of the pdf file
              Hwnd = FindWindow(vbNullString, "Test.pdf - Adobe Acrobat")
              If Hwnd Then
                  'Close the file
                  PostMessage Hwnd, WM_CLOSE, 0, ByVal 0&
              End If
              End Sub
              

               

              Edit: I would also contact your VAR to make sure that the API team is aware of the issue and see if a SPR has been issued already.

                • Re: Bug in IModelDocExtension.SaveAs method
                  Koji Eguchi

                  Thank you.

                   

                  I think it's a good idea.

                  However, if the file saved in the shared folder is opened on another computer, will not the same problem occur?

                   

                  I am not good at English.

                  I am very happy if you contact the API team.

                    • Re: Bug in IModelDocExtension.SaveAs method
                      Matt Bieringer

                      Koji Eguchi,

                      You would have to contact your VAR to have them submit an SPR to API. That being said the following code that I found here (https://support.microsoft.com/en-us/help/291295/macro-code-to-check-whether-a-file-is-already-open) will check to see if a file is open or in use and will tell you if someone on the network is using the file.

                       

                       

                      Sub TestFileOpened()
                          ' Test to see if the file is open.
                          If IsFileOpen("Y:\Users\mbieringer\test.pdf") Then
                              ' Display a message stating the file in use.
                              MsgBox "File already in use!"
                              ' Add code here to handle case where file is open by another
                              ' user.
                              '
                          Else
                              ' Display a message stating the file is not in use.
                              MsgBox "File not in use!"
                              ' Add code here to handle case where file is NOT open by another
                              ' user.
                              '
                          End If
                      End Sub
                      ' This function checks to see if a file is open or not. If the file is
                      ' already open, it returns True. If the file is not open, it returns
                      ' False. Otherwise, a run-time error occurs because there is
                      ' some other problem accessing the file.
                      Function IsFileOpen(filename As String)
                          Dim filenum As Integer, errnum As Integer
                          On Error Resume Next   ' Turn error checking off.
                          filenum = FreeFile()   ' Get a free file number.
                          ' Attempt to open the file and lock it.
                          Open filename For Input Lock Read As #filenum
                          Close filenum          ' Close the file.
                          errnum = Err           ' Save the error number that occurred.
                          On Error GoTo 0        ' Turn error checking back on.
                          ' Check to see which error occurred.
                          Select Case errnum
                              ' No error occurred.
                              ' File is NOT already open by another user.
                              Case 0
                               IsFileOpen = False
                              ' Error number for "Permission Denied."
                              ' File is already opened by another user.
                              Case 70
                                  IsFileOpen = True
                              ' Another error occurred.
                              Case Else
                                  Error errnum
                          End Select
                      End Function
                      

                       

                      Hope this helps.

                  • Re: Bug in IModelDocExtension.SaveAs method
                    Koji Eguchi

                    The same problem occurs not only in 3D PDF but also in iges, x_t and STEP.

                    It may possibly occur in other file formats as well.