This example shows how to export DWG files across multiple folders at a time. It uses an enhanced batch file that includes error detection and logging.
The batch file receives three parameters each time it is executed:
In the previous example, every DWG must have a corresponding export profile. This example allows you to use either a corresponding profile or a default one. If a DWG file does not have its own profile, it uses the default one.
The log file captures the entire command window for each DWG file. It uses the AutoCAD command copyhist, which moves the command window history to the system clipboard. This example uses winclip.exe, a free open-source tool, to paste it to the log file.
You can call the batch file from an "outer" batch file: a master batch file that contains only calls to the subordinate batch file, providing the parameters.
For example, suppose you have drawings for three cities. If the batch operation exports a folder of drawings for one city, the outer batch file might contain the following:
batchexport Redding\DWGs Redding\SDFs Redding\DefExport.epf batchexport Spokane\DWGs Spokane\SDFs Spokane\DefExport.epf batchexport Dubuque\DWGs Dubuque\SDFs Dubuque\DefExport.epf
To use this method, either specify a different export.log for each call, or move the line if exist export.log del export.log to the outer batch file. Otherwise each call overwrites the previous log.
The following sample production batch file is called batchexport.bat. Create it in Notepad, as you did in the previous procedures.
@echo off setlocal rem Get and verify the command parameters set srcDir=%1 set outDir=%2 set defEpf=%3 if '%srcDir%' == '' goto usage if '%outDir%' == '' goto usage if '%defEpf%' == '' goto usage if not exist %srcDir% ( echo Source Directory "%srcDir%" not found. goto done ) if not exist %srcDir%\*.dwg ( echo No DWG files found in "%srcDir%". goto done ) if not exist %outDir% ( echo Destination Directory "%outDir%" not found. goto done ) if not exist %defEpf% (echo Default Export Profile "%defEpf%" not found. goto done ) if exist export.log del export.log rem Loop through the DWGs, exporting each for %%f in (%srcDir%\*.dwg) do ( if exist %outDir%\%%~nf.sdf del %outDir%\%%~nf.sdf echo. >> export.log echo ******* EXPORTING %%f TO %outDir%\%%~nf.sdf ******* >> export.log echo ******* EXPORTING %%f TO %outDir%\%%~nf.sdf ******* rem Create the Export Script ... echo _-mapexport> export.scr echo FDO_SDF>> export.scr echo %outDir%\%%~nf.sdf>> export.scr echo _yes>> export.scr if exist %%~df%%~pf%%~nf.epf ( rem Use a profile that has the same name as the DWG echo %%~df%%~pf%%~nf.epf>> export.scr ) else ( rem Use the default profile echo %defEpf%>> export.scr ) echo _proceed>> export.scr echo _copyhist>> export.scr echo _quit>> export.scr "C:\Program Files\AutoCAD Map 3D 2009\acad.exe" %%f /nologo /b export.scr winclip -p >> export.log ) goto done :usage echo USAGE: %0 [sourceDir] [destDir] [defaultExportProfile] echo example: %0 Redding\dwgs Redding\sdfs Redding\defExport.epf :done
You created an enhanced batch file with error detection and logging to export DWG files across multiple folders at a time.