Help using API's SaveAs to export PDFs of drawings (Error 0x800757)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm trying to learn a little of the Inventor COM API. As a proof of concept, I'm trying to open Inventor, open a drawing file, and then save a copy of as a pdf.
Here's my code (Python):
import os
from win32com.client import *
print("Test")
app = Dispatch("Inventor.Application", True)
app.Visible = True
print("Inventor opened")
desktop = os.path.normpath(os.path.expanduser("~/Desktop"))
app.Documents.Open(os.path.join(desktop, "Drawing1.idw"))
print("File opened")
file = CastTo(app.ActiveDocument, 'DrawingDocument')
file.SaveAs(os.path.join(desktop, "Drawing1.pdf"), SaveCopyAs=False)
print("PDF saved")
file.Close()
The script fails at SaveAs with the following output.
Test
Inventor opened
File opened
Traceback (most recent call last):
File "C:/Users/jamle/PycharmProjects/Tests/Test.py", line 13, in <module>
file.SaveAs(os.path.join(desktop, "Drawing1.pdf"), SaveCopyAs=False)
File "C:\Users\jamle\AppData\Local\Temp\gen_py\3.7\D98A091D-3A0F-4C3E-B36E-61F62068D488x0x1x0\DrawingDocument.py", line 175, in SaveAs
, SaveCopyAs)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024809), None)
Process finished with exit code 1
Error -2147352567 (0x80020009) is the generic Exception occured COM error code. Which isn't very helpful. Error -2147024809 (0x80070057) is listed as "One or more arguments are invalid". The only change I can make to get this error to not occur is to change the new file to also be an IDW rather than a PDF.
Edit: If I save as a DWG, it works. It's just PDFs that don't. I note that that when I use Inventor manually and click SaveAs, my only options are IDW and DWG...
I was under the impression from this article that SaveAs could be used to change the format of the drawing. However, it appears not. What command should I be using instead?
As a bonus question, can I perform this action (saving an IDW or DWG as a PDF) without having to open inventor and the drawing? i.e. Can I find a drawing object from a filepath and call it's SaveAs (or whichever other) method without opening it?
Thanks for the help