Macro Tips

Defining a macro

CC3 keeps a single dictionary or table of macro definitions in memory. CC3 builds its macro table from a macro file (like fcw32.mac) loaded with the LOADMACM command. When you load a macro file, pre-existing macro definitions are cleared and replaced by the new macros in memory.

Use the EDITMAC command [Macros > Edit Macros] or a plain-text editor to create and edit the macro file.

When editing macro code, begin each macro with the MACRO command and the name of the macro. End each macro with the ENDM command on a line by itself. When your macros are thoroughly tested, use SAVEMAC to save them in a macro file with the type extension .mac.

To run each macro, type its name at the "Command:" prompt. You can also add it to CC3’s menus or Toolbars.

Macro names

A macro program or variable name can be any combination of characters ended by a space or semicolon—any word. Names can be as long as you want, but shorter names result in faster-running macros, because CC3 has to read and interpret each character every time you run the macro.

There are three ways to store text in a macro name:

·   The MACRO command defines names that can be programs or variables;

·   The Get commands like GW (Get Word) store data in names that are usually used as variables;

·   Within a macro definition, you can define a word as a label by preceding it with a colon (:). Several of the special macro commands jump to labels.

Delimiters

A delimiter tells CC3 where a command or parameter ends. A delimiter can be a:

·   Space ( ),

·   Semicolon (;),

·   Equal sign (=),

·   ENTER key (carriage return),

·   TAB key, or

·   right mouse button.

When you define macros, you should keep these rules in mind:

  1. Some commands require an extra delimiter before your macro can continue to the next command. These include:

·   Commands that automatically repeat or continue until you press the right button to end them. Examples include many DRAW commands such as LINES and PATHS.

·   Commands that switch to a text window, requiring a key or button press to return to the drawing window. Examples include COUNT and LIST.

·   Commands like DISTANCE (in the Info menu) that display an alert box.

  1. SPACEBAR or TAB is always a delimiter except in the parameters (responses) that follow these commands:

·   ^Dprompt (Some text that asks for some input).

·   In values to be entered in editable dialog-box items.

·   TSPECF, which allows spaces in the True Type font name.

  1. SEMICOLON (;) is always a delimiter inside a macro definition. Because a semicolon does act as a delimiter in a script or macro, it is impossible to include literal semicolons in macro parameters.

  2. ENTER (carriage return) and the right mouse button only work from the keyboard. CC3 "counts" the carriage returns that end each line in a macro, menu, or script file.

Function keys

A function key (for example, F2) is a special kind of macro name. The function key F1 is very special: it provides context-sensitive help anywhere in the program and can not be used for anything else. Also, the F10 key is used by Windows to access the Menu bar, as is the ALT key. CC3 recognizes the rest of the function keys, the 10 standard function keys (F2-F9, F11, F12) and the same keys combined with the CTRL key and/or the SHIFT key. You can refer to a function key by its name (F2, CF1, SF6, SCF9, etc.), or just press the key or key combination.

To define a function key in a macro file, enter MACRO, then the name of the function key (F4, SF1, etc.), then the text you want to store in it. Enter ENDM on a line by itself to end the definition. This example in a macro file stores the modifier TAN (Tangent) in F9:

MACRO F9
TAN
ENDM

Function key variables are also useful when you are working within CC3 for storing a point or a value to use over and over during a work session. Define the function key with the MACRO and ENDM commands, or use a get command like GP (Get Point) to store data in a function key.

Note: In CC3’s menu file fcw32.mnu, several function keys have been pre-defined to select modifiers. For example, F4 enters the CEN (Center) modifier. Several CTRL+ALPHA keys (^A, ^S) are also defined there.

Making Macros Auto-Repeat

If the 1st character of a menu or toolbar MACRO command starts with "|", then the macro name becomes the repeat command.

Programming macros

  1. Unlike true programming languages, a macro language does not know the difference between a macro used as a program, a macro used as a variable (a point, value, or other data), and literal text (a CC3 command, a file name, or text to be drawn). It is up to you to avoid name conflicts.

  2. Terms that would be macro expanded can avoid expansion by preceding them with an exclamation mark (!). This lets you define a new macro called COLOR that can call !COLOR (CC3 color command) inside itself yet use the original command.

  3. Within a macro table, make sure that each variable, label and macro name you use is unique. Also, never use a CC3 command (text equivalent) as a macro name (unless you want to redefine what that command does). Never use numbers as macro or variable names. Try to avoid using file names. If you write macros for other users, consider starting all macro, label, and variable names with a dollar sign ($) or some other unlikely character to avoid name conflicts.

  4. Variables are never further expanded. A value defined with MACRO/ENDM will be expanded as long as necessary.

  5. To run a macro, type its name. You can also run a macro by including its name in the menu data part of a menu item, if you make sure the necessary macro definitions get loaded (as a .mac file) along with the menu (.mnu).

  6. A macro can call another by name, effectively running it as a subroutine. CC3 allows up to 16 levels of nested macros. When CC3 finishes performing the text in the called macro, or executes an EXITM command, control returns to the next command in the calling macro. Under some conditions (such as the user canceling by pressing the right button at a prompt), you may want to end all macros and return to the Command: prompt without returning to the calling macro. To do this, use EXITAM (Exit All Macros).

Related Topics

Understanding Macros

Load Macros

Edit Macros

Save Macros

Macro Command Reference

Alphabetical List of Macro Commands