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 CUI Editor.
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 this macro 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.
Verify Macro Characters
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.
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
Terminate Macros
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.
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).
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.