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 and later.
Here are 3 important points that you need to know about scripts:
- Scripts are text-only (ASCII) files. You usually create them in Notepad.
- They have an SCR filename extension, so be sure to save them that way.
- Scripts use command-line syntax only. They can’t access dialog boxes, toolbar buttons, etc.
Follow these steps to create a script file:
- Set the FILEDIA system variable to 0, to stop dialog boxes that access files from opening.
- 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.
- 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.
- Enclose layer names or files names (and file paths) that contain spaces in quotation marks.
- Insert comments periodically for explanation. To insert a comment, precede the text with a semicolon.
- Save the file with an SCR filename extension, by typing .scr after the file name.
- 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:
- Right-click the shortcut and choose Properties.
- Click the Shortcut tab.
- 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:
- Click OK.
- Double-click the shortcut to open AutoCAD and run the script.
/b script_name
Autodesk provides a free program for running script files on multiple drawings, called ScriptPro. The file is called scriptpro.exe.
Related posts:




Nice tips. I’ve been scripting for a few months, and can’t find a way do a new task. I want to apply a style to existing text in a file. chprop doesn’t get me there and _properties won’t allow scripting commands against it. Anyone have a way in scripting to apply a style to selected text?
I found this by trial-and-error. When I selected some text and chose a new style from the list, I saw _optchprop on the command line. It’s not listed as a command in Help, but I can type it on the command line. Interestingly, I have to type the underscore (which is normally there for purposes of translating AutoCAD). So, I selected some text and tried it. I did everything on the command line. That’s the first step to creating a script, so see if it works for you.
Command: _optchprop 1 found
Enter property to change [Textstyle/Dimstyle/tAblestyle/Mlstyle]: t
Enter text style name: times
Enter property to change [Textstyle/Dimstyle/tAblestyle/Mlstyle]:
I have been trying to create a script file that will change what I have in my viewport to plot at 50% shading using a ctb file.
I can not get it to work. I am having to go into my viewport and then select the layers that I want plotted at 50% shading.
Is this possible to do? If so, can you provide how to get this accomplished?
Thanks
Maybe one of our readers will come up with a solution for you.
Hi Elien,
I’m trying to use script file to stretch the pline and moved ucs to the locations. But it does not working well. Please help and email me back.
Thanks,
Shawn
Elien,
I go through the steps but I cannot open the .scr file through the script command in AutoCAD 2011. Any suggestions?
What happens when you choose the .scr file in the dialog box and click Open?
Ellen, can I open files in black and white only using startup.scr?
Thank you.
I haven’t heard of the concept of opening a file in black and white, just plotting. One of these blog posts might help you:
http://www.ellenfinkelstein.com/acadblog/know-what-your-plot-will-look-like-when-you-use-plot-styles/
http://www.ellenfinkelstein.com/acadblog/tutorial-create-a-plot-style-color-dependent/
http://www.ellenfinkelstein.com/acadblog/plot-on-a-black-white-printer/
Hi Allen
I’m trying to find a list of commands I can use in script files, I read somewhere that “if” and other commands are possible.
I’m trying to right a script to rename layers and set new colors and line types but I’m new to scripts and having trouble making it work.
Not all drawings will have all layers, so not sure what will happen when the script doesn’t find a layer it’s looking for?
Scripts don’t have “if.” If you want “if”
you’ll need AutoLISP or another programming language.
Scripts just execute commands. If you can’t do it by typing on the keyboard, you can’t do it in a script.
The value of scripts is that you can use them over and over and they can do long lists of commands, even on many drawings.
Hi Ellen,
Very nice advises, i really appreciate it, my query is similar to this blog, i have a file in my c drive, location is C:\Documents and Settings\urathore\Desktop\INNOVATION\TEST_120503_001.test110147160113_003.dwg, meanwhile my script is saved with the same folder with USMAN120507.scr.
My confusion is that in that case what i am doing is that i am creating shortcut of test110147160113_003.dwg and then in TARGET option of the shortcut i am writing ahead of the path (as advised above) /b USMAN120507.scr (even tried without .scr as well), the test file opens but the script does not run, i have successfully run the script within the test file many times, perhaps i am doing it all wrong.
Will really appreciate your gracious guidance !