Writing Scripts
One of my favorite things about using AutoCAD is the ability to write and run scripts to help me do repetitive tasks quickly. A script is a series of commands (just like you type into the command line) that you can save in a text file and run on any drawing whenever you need it. Since it is saved in a text file, you can easily share it with colleagues who might need to use it. I have a library of scripts for repetitive tasks we do at work on a regular basis. Here is how to get started writing a script.
Let’s get started with something simple. For example, you might want to print a bunch of drawings with specific settings. You could hit print in each drawing, change the settings, and then let it print - or you could simply run a script on each drawing to do the same thing.
HINT: When I get an idea for a script, I usually do a dry-run by typing each command into the command line to see how it works. As I do, I write the same keystrokes in Notepad to generate my script.
To create this script, open Microsoft Notepad (or another text editor). Type commands into Notepad just like you would on the command line, hitting enter after each command. Here is an example of how a printing script might look:
-plot Y \\networkprintlocation\MY_PRINTER_NAME Oversize: Arch D I L N e 1:1 C Y Standard.ctb Y Y N N N Y Y
Notice there is an extra return after the last “Y”. Each line return is like hitting enter on the command line. Whenever you would hit enter on the command line, hit enter in Notepad.
When you are finished save the file with a .scr filetype. For example you might call this one “print.scr” and save it somewhere on your computer or network.
To run the script in AutoCAD, type SCRIPT (or use the alias SCR) on the command line and browse to open your script. It will run immediately. If it does not run as expected, hit F2 to check where it got hung up. Depending on how complex a script is, sometimes you will need to do this a few times to debug a script.
Did you know that you can plug in AutoLISP code into your scripts? Let’s say you want to create a selection set of objects on a certain layer and change them to another layer. You could write a script like this:
(ssget "x" (list (cons 8 "WrongLayerName"))) chprop previous la RightLayerName
Using scripts for productivity get’s even better with ScriptPro - a program Autodesk created to allow you to run scripts on multiple drawings at once.
Now that’s lazy!
Writing Scripts…
You’ve been kicked (a good thing) - Trackback from CadKicks.com…
Very cute command and would like top know more about script, how can i learn. thanks for your help to CAD community
Binu Mathew,
If you have any specific questions about writing scripts, feel free to ask them here in your comment. I’d be happy to help.
Thanks for stopping by!