Friday, March 6, 2015

Running Scripts on Multiple Files – AutoCAD Electrical

Several times now I have been asked how to “do something” to every drawing in the project. The last one to come across my desk was to freeze all layers on all drawings project wide. AutoCAD Electrical actually has some really good tools for running scripts. I find myself turning to it even for non Electrical needs quite often.

Here are some examples I have encountered recently:
Updating the company address, or copyright year, on all title blocks
Swapping title blocks on all drawings (Swap/Update Block)
Zoom Extents, set limits, and export PDF
Add company standards (layers, dim styles, ect) to all drawings
Freeze all layers

Pushing a Script Project Wide

This method involves a script file (.scr). A script file consists of only what you would type in the command line. Start Notepad and type everything command there as you would in the Command Line. For example to freeze all layers and then do zoom extents your script file would look like this.
image

To test a script file simply drag and drop the file into the drawing window. The script will run and you will quickly see if it runs properly. If you script is complex, consider adding notes. Any line started with a semi-colon is ignored by the script file. Add comments starting with a semi-colon to make future edits easier to understand.

And now to run this script on an entire project. Make the desired project active and then choose Utilities from the Project tab.
image

In this dialog, select ‘Run command script file’ and select the script file to run. After pressing OK the option for project wide is the default.
image
 image

Pushing a Script On All Drawings in a Folder

This option is hidden under the Symbol Builder drop down menu. The command is Modify Symbol Library. This utility can be used to simply run an AutoCAD command or to run a script on all files in a folder.
image

The first thing the command asks for is a folder. After selecting the folder, the following dialog displays. I recommend creating a test folder with only a few drawings to prove out the script before running on a large number of files.
Check the Run AutoLISP box and enter a LISP command.
image

This dialog checks your LISP command for proper formatting. If something is wrong the following will display.
image

Any AutoCAD command can be run in LISP by simply starting with “command”. Remember all LISP lines are enclosed in parentheses ().

I entered the following to run my script file… (command "_.script" "C:\LayerLock.scr")
Press Start and sit back while AutoCAD Electrical does all the work.

No comments:

Post a Comment