Command scripts and macros

Command scripts offer an easier and faster way to execute functions that you use repeatedly. Macros are text files that contain command scripts.

Learn more:

Command scripts

Command scripts offer an easier and faster way to execute functions that you use repeatedly. You can define multiple commands and their inputs into a single command script. Command scripts are used in

  • Drop-down menus and keyboard menus to define the menu action

  • Toolbars and icon menus by editing the menu file in an text editor

  • Macros, which are a collection of commands to be executed consecutively

For more sophisticated automation, we recommend that you use the K programming language or the KDS C/C++ programming interface.

Command script syntax

The maximum length for command scripts is 256 characters. The following special characters can be used:

  • ^# – Corresponds Enter. You must insert this, for example, at the end of a command, just as you would press enter when you have typed a command on the command line. You can use space to separate different parts of a command script. An exception is when you enter text within a command script. The program understands a space as a part of the text string, so a ^# must end a text string.

  • ^? – Prompts the users to enter the required input. If, for example, a command script starts the LINE command followed by a ^?, that would require the user to enter the line start point.

  • ^& – Restarts the command script. This is used at the end of the command script to start the same script over and over again. It should not be used in scripts that don’t have a break point, such a ^? character. There is no need for ^# at the end if there already is a ^&.

  • ^E – Corresponds Esc. This is used at the start of a script to ensure, that there are no commands running when you start the script.

    Note: The E must be a capital letter.

  • ^K – Checks whether the selected object is currently selected in grip edit. If so, the subsequent ^E^E sequence is bypassed.

  • | – Pipe symbol. This is used to enter transparent commands. Commands following this symbol must, naturally, be transparent commands.

The command script does not necessarily include answers to all the questions. The command script can be stopped before it reaches the end, in which case the user will take care of the rest. Then, the command script LINE^# will start the line drawing function but after that everything works as if the command had been entered via the keyboard. Also, if the symbol includes several prompt attributes whose values are needed when fetching the symbol, they do not need the ^? sequence.

The following command scripts are, therefore, equal:

LINE^#

LINE ^? ^?^#

Macros

A macro is a text file that contains command scripts. Macros can be written with a text editor. If you use a word processor, you must save the macro in text format.

The following rules apply:

  • Macro is a text file that must have the .mac extension.

  • The macro file name may not be the same as a command name. The program will first look for a program command, then a macro and last a K program.

  • You can write comment lines into a macro by starting the line with a semicolon, for example:
    ; This is a comment line.

You start a macro just like any other command, by entering the name on the command line or by placing it in a menu. For example, you can start a macro named Start.mac

  • From the keyboard: >Start

  • From a drop-down menu: "&Start", "^E^Estart^#", "Run Start macro"

  • From a text menu: Start =start^#

  • From a keyboard menu: "F1","start^#"