AutoCAD Scripting
Type your AutoCAD commands into a script file (a text file with an .scr extension)
and then tell CAD to run the thing using the SCRIPT command.
That's pretty much it.
Generally, just type in the commands and arguments just as you would at the
command line. You can hit enter after each command/argument or you can usually
use a space to separate them. It works out rather well if you put each command
and its arguments on one line separating them with spaces:
-style ROMAND romand.shx 0.25 0.85 0 No No No
TEXT 0,3/64 0 TITLE
-style ROMANS romans.shx 0.125 0.85 0 No No No
TEXT TL 0,-3/64 0 SCALE: 1/8" = 1'-0"
LINE 0,0 3,0
This script quickly creates a drawing title with a scale by creating a style
named ROMAND, creating a line of ROMAND text for the title, then setting up
a ROMANS style and creating text that describes the scale just below the title,
and finally drawing a 3" line between the text.
After you have a script typed up, save it with the .SCR extension. Type SCRIPT at
the command line to display a dialog box which allows you to select and run
your script file.
AutoCAD Startup
You can run a script when starting up AutoCAD from a shortcut by adding the "/b" switch
followed by the path and name of a script file (the path isn't necessary if
the script is in the search path). The script is effectively run after CAD
is loaded and the intial drawing is created.
Slide Shows & Animations
You can create slide shows or sequences with script files using the following
commands in your scripts:
- DELAY - pause execution of the script
commands for a number of milliseconds.
- RESUME - resume a script that was paused
(using the escape key) or stopped because of an error.
- RSCRIPT - repeat the script from the
beginning.
Slide shows or animations are created using the DELAY command between commands
that display slides, move/add/erase objects, pan, etc. Use the RSCRIPT command
as the last command in your script to have it repeat endlessly.
Watch It
Scripts don't work so well with dialog boxes, so be sure to use the command
line version of CAD commands. Many commands have command line versions that
have the same name but with a hyphen (-) prefix.
While writing the example above, I found that the DTEXT command
doesn't properly work in a script for whatever reason, so there will be some
obstacles in scripting. It's best to try a different command or approach if
you run into a command that doesn't work.
See Also
The AutoCAD help section "Customization Guide" & "Slides
and Command Scripts" contain the info on using scripts.
Other forms of customization such as menus/toolbars or AutoLISP allow user
input for any arguments in the middle of commands.
- Menus or toolbars create an easy to use interface inside of AutoCAD to
let users run commands. That plus the ability to let the user supply command
arguments make menus/toolbars a more usable solution for command automation.
- AutoLISP allows full programmatic control, including allowing user input
and calculations based on user input.
© Eastern Virginia AutoCAD User Group |