Command scripts and macros

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.

  • 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. Contact Technical support for more information about the K programming language and the KDS C/C++ 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. The E must be a capitol 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.

Macros

A macro is a text file that contains command scripts. You can start a macro just like any command by its name.

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 file name 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.

Using macros

You start a macro just like any other command, by entering on the command line or by placing it in a menu. The following shows you how a macro named Start.mac could be added to different menus.

Drop-down menu: "&Start", "^E^Estart^#", "Run Start macro"

Text menu: Start =start^#

Keyboard menu: "F1","start^#"