ellen finkelstein logo

Ellen Finkelstein.com
AutoCAD PowerPoint About Links
       

Over 130 AutoCAD tips and tutorials!

AutoCAD Tips
AutoCAD Tips Blog

Get free tips!
Sign up for our monthly tips newsletter. Free, bonus e-booklet!


RSS: What is it? Why do I want it? How do I get it?

Add to My Yahoo!
Subscribe with Bloglines

Buy a Book

E-mail This Page 
to a Friend

Submit a tip! If you include your name and I post your tip, I'll give you credit.

AutoCAD Tips & Tutorials

Tutorial: Automate tasks with a script file

A script is a macro, a list of commands that you can run all at once, and as many times as necessary, allowing you to automate tasks that would take a long time if you did them manually. Scripts can be very powerful and you can run them on objects in one drawing, or on many drawings. Scripts have been around for many years and many people have a library of many scripts that they use.

See my tip, Record Actions with the Action Recorder, for a way to record your actions in AutoCAD 2009.

Here are 3 important points that you need to know about scripts:

  1. Scripts are text-only (ASCII) files. You usually create them in Notepad.
  2. They have an SCR filename extension, so be sure to save them that way.
  3. Scripts use command-line syntax only. They can't access dialog boxes, toolbar buttons, etc.

Follow these steps to create a script file:

  1. Set the FILEDIA system variable to 0, to stop dialog boxes that access files from opening.
  2. Run through the steps that you want to automate, using the command line only. Write down (or type in Notepad) the steps. You can copy your command line entry directly to Notepad. Press F2 to open the AutoCAD Text Window for that purpose.
  3. Press Enter at the end of each command or use a blank space, which is the equivalent of pressing Enter. The script reads every space, so you need to get it exactly right! The script is easier to read if you put each command on its own line.
  4. Enclose layer names or files names (and file paths) that contain spaces in quotation marks.
  5. Insert comments periodically for explanation. To insert a comment, precede the text with a semicolon.
  6. Save the file with an SCR filename extension, by typing .scr after the file name.
  7. Set FILEDIA back to 1.

To run and test the script file from within a drawing, use the SCRIPT command. A dialog box opens, where you can choose your script file. Click Open and the script runs.

Let's say that you want to run a script file on more than one drawing. You can use the OPEN, CLOSE, and QSAVE commands to open drawings, run some commands, save the drawings, and then close them. You can still start the script from within the 1st drawing, but you can also start a script file as you open AutoCAD.

To do so, you change the expression that Windows uses to open AutoCAD. The best way to do this is to use the shortcut on your Desktop. Follow these steps:

  1. Right-click the shortcut and choose Properties.
  2. Click the Shortcut tab.
  3. At the end of the existing expression (which reads something like C:\Program Files\AutoCAD 2009\acad.exe) add a space and then the following:

/b script_name

  1. Click OK.
  2. Double-click the shortcut to open AutoCAD and run the script.

Autodesk provides a free program for running script files on multiple drawings, called ScriptPro. The file is called scriptpro.exe.

More Tips

 

Page copy protected against web site content infringement by Copyscape


Books by Ellen

New!
AutoCAD 2009 and AutoCAD LT 2009 Bible

This is the 9th edition of this book! Completely updated to conform to the new interface and, of course, it covers all the new features, such as the ribbon, Quick View, ShowMotion, the View Cube, the SteeringWheel, and more.

AutoCAD 2008 and AutoCAD LT 2008 Bible
Learn the great new features with wide application to all disciplines. Get the most comprehensive book on AutoCAD! DVD contains a 30-day trial of AutoCAD and AutoCAD LT. Thorough exercises guide you through each feature.

AutoCAD 2007 and AutoCAD LT 2007 Bible 
Discover the 2007 features, especially the radically improved 3D tools. CD has AutoCAD 30-day trial, 3rd-party software, and drawings for exercises.

AutoCAD 2006 and AutoCAD LT 2006 Bible 
Understand and use the 2006 features, including dynamic blocks and the new method of customizing menus and toolbars. CD-ROM has AutoCAD trial, software, and drawings for all exercises.


AutoCAD 2005 and AutoCAD LT 2005 Bible
Fully explains latest 2005 features:  tables, fields, and sheet sets. For the first time, covers AutoCAD LT! CD-ROM comes with software and drawings for all exercises.


AutoCAD 2004 Bible

Covers all features in detail. Hands-on exercises. Over 1300 pages + CD-ROM with software and drawings for all exercises.

                                  Home  |  AutoCAD  |  PowerPoint  | E-StoreAbout  | Links | Contact | Site Map
Copyright Ellen Finkelstein, Inc.