The Power of Macro
What is a Macro?
A macro (in many different programs) can be defined as a way to automate a task that you perform repeatedly with more than one command or keystroke. In +AutoCAD macros can be shortcuts to a series of commands to help make the process of design more efficient. You can use the action recorder to record a series of commands and build a macro then run it automatically to repeat a series of steps. To write a macro, you type the commands in the macro properties section as you’d type them in at the command line. If a command displays a dialog box, you would place a dash in front of the command to suppress the dialog box.
excerpt from "Mighty Macros: Powerful Commands to Pump up Productivity" by Sam Lucido AU 2013"
From Autodesk Help
A macro can contain commands, special characters, DIESEL (Direct Interpretively Evaluated String Expression Language) or AutoLISP programming code. (AutoLISP is not supported by AutoCAD LT)
Note: As AutoCAD-based products are revised and enhanced, the sequence of prompts for various commands (and sometimes command names) might change. Therefore, your custom macros might require minor changes when you upgrade to a new release of you application. You add macros to interface elements by using the Customize User Interface (CUI) Editor. Select an existing command or create a new command in the Command List pane. Enter macros in the Macros section of the Properties pane. There are no length limitations for macros. However, you do need to know how specific characters are used in macros and be aware of other considerations or limitations.
Macro Basics
A macro defines the action that should be performed when a user interface element is used. It can be as simple as a command (such as circle) and include special characters (such as ^C^C).
For example, the macro ^C^C_.circle \1, draws a circle with a radius of 1 unit. The components that define thismacro are explained in the following table.
Cancel the Active Command
When a button in the user interface is clicked, the macro assigned to it is executed in the current context of the program. This means that the macro will attempt to provide responses to the current prompt. If you want to make sure that no command is currently active when the macro is executed, prefix your macro with the ^C command sequence. Although a single ^C cancels most commands, ^C^C is required to return to the command prompt from a dimensioning command and ^C^C^C is required based on the current option of the -LAYER command. ^C^C handles canceling out of most command sequences and is the recommended sequence to use.
Every character in a macro has a significant meaning, even a blank space. When you place a space at the end of the macro, it is interpreted as if you had pressed the Spacebar or Enter to complete the command.
Use Standard Commands in Macros
Commands that are part of AutoCAD or AutoCAD-based products should be prefixed with a period character (.). The period character allows the standard command to be used even if it has been undefined with the UNDEFINE command. This precaution makes the macro predicable when it is used on other computers that share the same customization (CUIx) file.
Note: Commands cannot be undefined in AutoCAD LT.
Use Single Object Selection Mode
Single Object Selection mode cancels the normal repetition of the Select Objects prompt in editing commands. After you select one object and respond to any other prompts, the command ends.
Consider the macro in the following example:
^C^C._erase single
This macro terminates the current command and starts the ERASE command in Single Object Selection mode. After the macro is started, you can either select a single object, or click a blank area in the drawing and specify window/crossing selection. Any objects selected using these methods are erased.
Repeat Commands in Macros
Once you have created a macro, you might want to repeat it several times before moving to a different command. In a macro, use a leading asterisk (*) to indicate that the command in a macro should be repeated until you press Esc or start another macro that begins with ^C.
The macros in the following examples repeat the commands:
*^C^C._move Single
*^C^C._copy Single
*^C^C._erase Single
*^C^C._stretch Single Crossing
*^C^C._rotate Single
*^C^C._scale Single
Note: You cannot use this feature to choose options, or for macros in image tile menus.
Some macros require special terminators. For example, the TEXT command requires you to press Enter rather than Spacebar to terminate the command and some commands require more than one press of the Spacebar or Enter to complete.
Two special conventions resolve these problems.
- A semicolon (;) in a macro is equivalent to pressing Enter.
- If a line ends with a control character, a backslash (\) or a semicolon (;), a blank space is not added after it.
Compare the following macros:
ucs
ucs ;
The first example starts the UCS command and, because the line ends with a space, the pressing of the Spacebar is simulated. The following prompt is displayed:
Specify origin of UCS or [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis] :
The second example starts the UCS command, simulates the pressing of the Spacebar, and then a press of the Enter is simulated which accepts the default value (World).
Suppress Echoes and Prompts in Macros
Characters in a macro appear at the Command prompt as though you had typed the characters from the keyboard. This display duplication is called echoing. You can suppress macro echoing with the MENUECHO system variable. If echoes and prompts from item input are turned on, a ^P in front of the macro will temporarily turn them off. You can also use ^Q in a macro to suppresses the display of all prompts and input from the Command Line history.
Here's the sample macro you may use:
Superpurge: (includes Regapps and WBlock)
^C^C-PURGE;A;*;N;AUDIT;Y; -PURGE;A;*;N;-PURGE;R;*;N;AUDIT;Y;-PURGE;A;*;N;-WBLOCK;
SuperSave:
^C^C -PURGE;A;*;N; -PURGE;A;*;N;AUDIT;Y;-PURGE;A;*;N;ZOOM;E;SAVE;CLOSE;
Checkout this sample quick video on how to create a command using macro:
Note: Don't watch this in full screen , use the theater mode. Quality of these video maybe blurred.