Macros and Scripts

This is the second of three blogs explaining how to manage system variables 

  1. This blog demonstrates a level of automation to change the variables and store them in toolbars.  

Scripts 

When saving the variable settings to an external file from the Systems Variable dialog box, you can save either a filtered list (by using the search with wildcards) or a selected list by selecting multiple variables (using the <CTRL> or <Shift> key to select more than one). If only one variable is selected, then all will be saved, as shown. 

 

 

You have the option of file formats, as shown: 

  • SVF is for reading (restoring) variables in the Systems Variable dialog box. 

  • SCR is for restoring the variables through the AutoCAD Script command. 

 

 

 

Script Files 

To use the script file, type Script in the Command Line, then browse to the script file (with a *.scr extension). Select the file to open it. AutoCAD reads each line as if it were typed in at the command line. It skips any line that starts with a semi-colon (;) – this usually precedes variables that are read-only and cannot be changed. 

You can also develop macros using such script formats. Similar to scripts, a macro is a series of keystrokes executed when the macro is launched. Scripts run the commands from the contents of a text file whereas macros run the commands from a text string within the macro, which is stored in the program. 

Macros can be defined as commands through the CUI interface where the following can be done, as shown: 

  1. Create a new command. 

  1. Search for commands (which then can be edited). 

  1. Name the new command. 

  1. Create the macro: 

a. Type in the commands exactly as you would in the command line. 

b. “^C^C” means <CTRL> C, <CTRL> C, which cancels any ongoing command. 

c. A space acts the same as an <Enter> key. 

  1. Assign an icon, or button image, to the command. 

  1. Drag the new command into the Quick Access bar. 

Note: you can also drag the command directly to the Quick Access Bar while it is listed in the CUI interface, as shown.