Automating the conversion of DWG files to PDF

Amyuni's Development Team would like to share with fellow developers general information about Windows and Web development. These are issues encountered by Amyuni's team and were either solved or pending solution.
Post Reply
Posts: 121
Joined: Fri Oct 14 2005
Location: Montreal

Automating the conversion of DWG files to PDF

Post by Devteam »

Converting a single DWG or other CAD drawing file to PDF is easy. Most applications have an export to PDF function or the drawing can be printed to a PDF printer such as Amyuni PDF Converter. Batch conversion of multiple DWG files to PDF or automating the conversion of multiple files when you only have a DWG viewer installed can be more elaborate. This is how we were able to implement the conversion for either one or multiple CAD drawings using the BatchConvert function of Amyuni PDF Converter.

First you need a good CAD viewer that can view and print good quality CAD drawings and that lend itself to be automated without too much trouble. The ideal candidate that we found is the DWGTrueView 2010 from Autodesk(r). Once the viewer is installed, you first need to tweak the registry as follows:
- Open the registry editor (regedit) and browse to the following location:
- Set the “Default” value to:
"C:\Program Files\DWG TrueView 2010\DWGVIEWR.exe" "%1" /b "c:\temp\plot.scr"

What this will do is run the c:\temp\plot.scr script whenever a Print command is requested. Here is a sample Autocad(r) script that instructs the viewer to print the drawing to the Amyuni PDF Converter printer:

Code: Select all

Amyuni PDF Converter
Once the script is saved under c:\temp\plot.scr, you can test it before moving further. To do so, right click on any .dwg file and select "Print." You should see the viewer opening up the dwg file, executing the above script and then closing the document. If there are any errors in the script, you will see them right away in the viewer's command window. If nothing happens, i.e. the viewer does not open, you should check that you entered the registry values exactly as shown above.

Once the script is validated, you can write another VBS script to automate the batch conversion of multiple drawings to PDF. Here is a sample VBS script:

Code: Select all

Dim cdi
Set cdi = CreateObject("CDIntfEx.CDIntfEx.4")

cdi.DriverInit( "Amyuni PDF Converter" )
cdi.FileNameOptionsEx = &H4003
cdi.DefaultFileName = "c:\temp\test.pdf"

cdi.BatchConvert "c:\temp\*.dwg"

Set cdi = Nothing
What is quite neat with the BatchConvert solution is that you do not even see the viewer opening up and closing each document separately, all the processing is done silently in the background.

Advanced users can do more sophisticated things such as generating layered PDFs from the source DWG drawing. To generate a layered PDF, each layer in the drawing can be printed to one PDF then all the layers merged together in a single PDF using the Merge method of Amyuni PDF Converter.
Amyuni Development Team

Efficient and accurate conversion to PDF, XPS, PDF/A and more. Free trials at -
Post Reply