Macro Examples

The following snippets of macro code show how some macro functions are implemented. If you attempt to duplicate them in your own macros, ignore the line numbers (they exist for reference purposes only).

ASKBOX

Syntax: ASKBOX

<title>

<message text>

<message text>

<blank line>

Use the ASKBOX macro command to receive yes/no feedback from the user. IFERR is set if the user clicks on No, and cleared if they click on Yes.

The following macro asks the user if the current color should be set to red (color #2). If the user answers Yes, the macro processes line 09. If the user answers No, the IFERR flag is set, so the macro jumps to line 10, which essentially ends the macro.

Note that line 03 defines the title of your message box. The following lines (05 & 06) define the text. Line 07 is intentionally blank, as it marks the end of the message box text.

image\DBX_Askbox.gif

0macro CC

0ASKBOX

0Change Color

0Would you like to

0change the color

0to red?

07

0IFERR fin

0color;2

1:fin

1endm

IFDEF

Syntax: IFDEF <variable> <label>

IFDEF checks to see if the specified variable has been defined. If it has, then the macro jumps to the specified goto label. If not, then the macro can then initialize variables. This is useful for ensuring that variables used later in the macro do indeed exist (an undefined variable in an IFx command causes a macro to get out of sync and fail).

The following macro is called by another macro. Line 02 contains the IFDEF command. If the variable WS has already been defined, the macro jumps to line 04 (the "Ok" label) and finishes. However, it the variable WS has not yet been defined, then it is created and initialized in line 03.

0macro RESET

0IFDEF WS Ok

0GV WS 0

0:Ok

0endm

SELREST

Syntax: SELREST

Please see SELSAVE for usage notes.

SELSAVE

Syntax: SELSAVE

The SELSAVE and SELREST commands are used together to save and restore the Select by modes, respectively. Without these commands, changed selection modes persist even after the macro has exited. To preserve the pre-macro SELBY mode, start your macros with SELSAVE, and finish them with SELREST.

The following macro simply draws a line from point (1,1) to point (3,3). But then it uses the SELBYP command to change the selection mode to Prior. Then it changes the color of line to blue (color #3), and the layer of the line to "Merge". The selsave and selrest commands assure that after the macro finishes, the original SELBY mode (usually Dialog or Popup) is restored. Otherwise, the next editing command would automatically select the valid Prior entity.

0macro LL3

0selsave

0line 1,1 3,3;

0selbyp

0changec 3

0changel Merge

0selrest

0endm