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.
- Open the drawing file.
- Save the drawing file as fileneme.PDF in the IModelDocExtension.SaveAs method.
- Close the drawing file.
- Start up Acrobat Reader DC and open filename.PDF.
- Open part file with SOLIDWORKS.
- 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.
SolidworksApi macros
Hi Koji,
Yes I have checked,it seems to be bug.
Thanks
Manikandan
Are both file in same folder/location? If not them you may not get any errors.
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)"
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.
Thank you
Yes, both files are in the same folder.
If you process the drawing file with the same code, the Return Value is False and Errors is 1 (swGenericSaveError).
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.
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.
,
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.
<p>Sub TestFileOpened()</p><p> ' Test to see if the file is open.<br> If IsFileOpen("Y:\Users\mbieringer\test.pdf") Then<br> ' Display a message stating the file in use.<br> MsgBox "File already in use!"<br> ' Add code here to handle case where file is open by another<br> ' user.<br> '<br> Else<br> ' Display a message stating the file is not in use.<br> MsgBox "File not in use!"<br> ' Add code here to handle case where file is NOT open by another<br> ' user.<br> '<br> End If</p><p>End Sub</p><p>' This function checks to see if a file is open or not. If the file is<br>' already open, it returns True. If the file is not open, it returns<br>' False. Otherwise, a run-time error occurs because there is<br>' some other problem accessing the file.</p><p>Function IsFileOpen(filename As String)<br> Dim filenum As Integer, errnum As Integer</p><p> On Error Resume Next ' Turn error checking off.<br> filenum = FreeFile() ' Get a free file number.<br> ' Attempt to open the file and lock it.<br> Open filename For Input Lock Read As #filenum<br> Close filenum ' Close the file.<br> errnum = Err ' Save the error number that occurred.<br> On Error GoTo 0 ' Turn error checking back on.</p><p> ' Check to see which error occurred.<br> Select Case errnum</p><p> ' No error occurred.<br> ' File is NOT already open by another user.<br> Case 0<br> IsFileOpen = False</p><p> ' Error number for "Permission Denied."<br> ' File is already opened by another user.<br> Case 70<br> IsFileOpen = True</p><p> ' Another error occurred.<br> Case Else<br> Error errnum<br> End Select</p><p>End Function</p>Hope this helps.
Thank you very much.
I post from Japan, so the reply will be delayed.
I read your message using the knowledge of English I learned and google translation, but it seems I made a mistake.
I will try out the code you taught.
I will contact my VAR in Japan.
It was very helpful.
Thank you.