Tuesday, October 7, 2014

Cust 37: Export Sheets to PDF: Part 4

...continued from Part 3

Declare two more variables one each to store the Drawing document name and the PDF file name:

Dim sPDFName As String = String.Empty
Dim sDrawingName As String = oDoc.FullDocumentName

The Drawing document's FullDocumentName property returns the path and the name with the .IDW extension which is then stored in sDrawingName.

To Extract the Path of the Drawing use the function:

Dim sPath As String = IO.Path.GetDirectoryName(sDrawingName)

Then build the full name with path for the PDF file as below:

sPDFName = sPath + "\" + System.IO.Path.GetFileNameWithoutExtension(sDrawingName) + ".pdf" ' or dxf, png, swf, dwg

You can even use the message box function the old style way to check if the PDF filename is build correctly:

MessageBox.Show(sDrawingName + vbCrLf + sPDFName)

The final step is to simply call the SaveAs function of the Drawing object to save the drawing in PDF format:

oDoc.SaveAs(sPDFName, True)

The beauty of the SaveAs function is it uses just the changed file extension to save the current document in any of the supported formats automatically.

To see the various formats apart from PDF that can be exported to, select Save As > Save Copy As...


In the Save Copy As... dialog observe the Save As type list and note the extensions in bracket.


You can use any of these extension in place of PDF in the oDoc.SaveAs argument.

Pick PDF and click the Options button. This brings up the PDF Drawing dialog where you can set the number of sheets to export to PDF. The last used manual setting is used by the API.


With the All Sheets option selected, the PDF will contain as many pages as the number of sheets in the drawing.


Try changing various extensions in the code and also check the corresponding options dialogs and the various settings for each file type. Note how the last used settings influence the outcome of the exported format from the program.

Full Index of Inventor Tutorials, Tips & Crosswords