I was recently asked a question about the best way to create a PDF file for every drawing in a specified directory and it’s subdirectories. My answer is to write a small Visual Basic application to do it. Visual Basic Express (which is free) is fully capable of creating an application like this.
Below is the minimal code to get all of the files within a directory and perform some type of process on each one. The first line calls the .Net GetFiles function and passes in the directory name, a search pattern, and an argument indicating that all subdirectories should also be searched. This used to be a lot of work in VBA and is now a single line with .Net. Next it iterates over the list of filenames that were found and opens each one in Inventor, calls the SaveAsPDF function, and then closes the document. The SaveAsPDF function is a function I wrote that’s not shown below but it calls the PDF translator and exports the drawing to PDF. By simply replacing the SaveAsPDF call with a call to a different function you can change this program to do any type of processing you want.
Dim drawings() As String = System.IO.Directory.GetFiles( _
' Iterate through the found drawings.
For Each drawing As String In drawings
Dim drawDoc As Inventor.DrawingDocument
drawDoc = invApp.Documents.Open(drawing)
' Save the PDF.
' Close the drawing.
The above code doesn’t have any error handling or any user interface. Once you add that and a couple of bells and whistles the code grows a bit. I’ve created a full application in Visual Basic Express 2010 that has a user interface and the bells and whistles. The user interface is shown below.
You can see in the image above that some files failed to process. This is because they were created in a later version of Inventor so the version of Inventor I’m using is unable to open them. The good news is that the program handles that case correctly and reports it.
The program is written to work with Inventor 2013 and later. You can download the executable here: SaveAsPDF_Exe.zip (28.5K)
And you can download the complete source code of the Visual Basic Express 2010 project here: SaveAsPDF_Source.zip (13.9K)