Command macros can contain commands, special characters, DIESEL expressions, or AutoLISP programming code.
You can define and then assign a macro to a command by modifying the Macro property of a command in the Customize User Interface Editor (Windows) or the Customize dialog box (Mac OS).
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 this macro are explained in the following table.
Components in CIRCLE macro |
||
---|---|---|
Component |
Component type |
Result |
^C^C |
Special control character sequence |
Sequence that is similar to pressing the Esc key twice. |
_ |
Special control character |
Indicates the command that follows should use the global command name and not the localized command name. |
. |
Special control character |
Indicates the command that follows should use the standard definition of the command, and not the redefined command that might exist. |
CIRCLE |
Command name |
Starts the CIRCLE command. |
Special character |
A space is like pressing the Spacebar while using a command. |
|
\ |
Special control character |
Creates a pause for user input; in this example it is a pause for the center point of the circle. |
1 |
Input value |
Response to the prompt for the radius of the circle; in this example it is a unit of 1. |
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.
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 (CUI/CUIx) file.
When you first create a macro, you commonly create it using the command names and option values in the language you are familiar with. Each command and option has a local and global name to allow your macros to be used on all of the different languages that AutoCAD supports. Non-English support does not require much additional work on your part, you precede each command or option with the underscore character (_). The underscore character signals to AutoCAD that the command name or option value should be translated before the it is executed.
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.
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
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.
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] <World>:
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).
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.