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
Set cdi = CreateObject("CDIntfEx.CDIntfEx.4")
cdi.DriverInit( "Amyuni PDF Converter" )
cdi.FileNameOptionsEx = &H4003
cdi.DefaultFileName = "c:\temp\test.pdf"
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.