Script procedures are one of the oldest, lowest tech forms of AutoCAD customization. A script is simply a file that contains the exact series of keystrokes required to make AutoCAD perform a given task. The script file is authored using a plain text editor (such as Notepad) and saved with an SCR extension for reading by AutoCAD’s SCRIPT command.
Two key characteristics of AutoCAD scripts should be pointed out before we proceed:
Scripts may only invoke commands that can be typed into AutoCAD’s Command: prompt. Therefore any task that requires dialog style commands is not a good candidate for scripting.
Scripts allow AutoCAD to run unattended thus permitting great productivity for repetitive operations like purging or plotting batches of drawings. They key strength is that scripts can open, save and quit drawings thus hopping between drawing sessions with ease.
Here’s a simple script example. Open a Notepad session and type in EXACTLY the following:
line 0,0 5,0 5,5 0,5 close zoom w -1,-1 6,6
Save the file to your hard drive as TESTING.SCR then start a session of AutoCAD and key in SCRIPT at the command line. When prompted for the name of the script file to run select the TESTING.SCR file you saved previously.
Other possibilities for scripting include using the -LAYER command to build long lists of layers. This script would add a layer called SKY and color it blue and set it to be the current layer:
-layer m sky c blue sky
I also like using the -PLOT command for detailed plotting configuration. From AutoCAD’s dialog line type in -plot and see where it takes you. You can then write scripts using the technique.
Lastly, a very nice script can be used to purge and zoom extents like this:
purge a * n zoom e
Note: AutoCAD scripts (file type SCR) should not be confused with Visual Basic Script (file type VBS), as the two have nothing in common.
March 28th, 2007 |
Comments are closed.
Robert has provided CAD management consulting, programming and training services for clients throughout the United States and Canada since 1991. Reach Robert at firstname.lastname@example.org