3. QUANTA Scripting Language


Contents

Introduction

page 109

Command Logging

page 110

Script Modification

page 110

Introduction to TCL Scripting Control

page 113

Appendix

page 115


Introduction

QUANTA is designed such that every mouse click corresponds to a typed ("keyboard") command. The QUANTA "record" mode saves all commands, whether from the keyboard or the mouse, into a single file. This consistency lets you record a movie-like script, illustrating and highlighting key points of a structure or interaction for a later presentation, with a minimum of effort.

The commands can be removed later if rotations and translations are not required for end use. The Record functionality may also be used for precisely recording a sequence of manipulations for an archive, or to generate commands to be used as the core of a more complex script (a "macro").

To generalize a script and to increase its power, you may use variable substitution and add flow-control commands. QUANTA supports a subset of the Tool Command Language (TCL) for this purpose. See Introduction to TCL Scripting Control on page 115. The addition of TCL commands and QUANTA command modifications must be done with a text editor.


Command Logging


Creating a QUANTA log file

Creating a QUANTA log file (record script) is straightforward.

1.   To begin recording commands, select File/Record Session/Start from the QUANTA interface menu.

2.   In the window, enter the file name for the script ("script.rec" for example), or type "record start script.rec".

3.   When you wish to stop, pause or resume recording, select the menu pulldown at File/Record Session or type in "record <keyword>" where <keyword> is "stop", "pause" or "resume."

Note: Scripts allow exact duplication of a QUANTA run, including translations and rotations initiated by the mouse. Unedited scripts can quickly become very large. See Script Modification on page 110 for information on trimming the size of log files.


Playing back a script

Depending on the script, you may need to reset QUANTA by closing files. QUANTA record scripts can be started in two ways:

1.   Use the interface menu (or its keyboard equivalent); for example File/Replay Session/Start >.

2.   Type:

Assuming a script name of script.rec, correct commands would be: @script.rec or @script.


Script Modification

Script modification is necessary when you want something other than an exact logging of a QUANTA session. QUANTA provides no tools for adding TCL commands or editing record files. Scripts are ASCII files; they can be modified using any text editor. Common modifications are script simplification (removing unnecessary commands), changes of the target of the scripts, or introduction of flow (looping and branch logic). Flow control is discussed in Introduction to TCL Scripting Control on page 113.


Script simplification

If a given script is not meant for visual illustration, the first step to simplify it is generally to remove some or all mouse-introduced translation and rotation and other related commands from the file.

QUANTA logs mouse-based rotation, translation, zoom, and z-clipping adjustment commands as relative motion commands. All begin with %MOUSE. Similarly, commands issued using the pseudo-dials box in QUANTA are logged as %TRANS.

QUANTA does record some movement-related commands. A record file can be significantly reduced in size by removing "redundant" %mouse commands. The following awk script does this:

If a script requires no structure movement, then all movement commands can be removed.

In UNIX a simple way to remove all %MOUSE commands is to filter them out using the "grep" command:

Table 28 displays a summary of the %MOUSE command parameters.

Table 28. MOUSE Command Parameters 
%MOUSE nn xxxx yyyy mp
nn
Function

2

xy rotation

4

z rotation

16

scale

18

xy translation

20

z translation

33

z clip width

Note the number (nn) is derived from a binary code:

xxxx and yyyy are the xy position of the mouse on the screen (screen size dependent).

mp = 1 when the mouse button is depressed. It signals the start position. mp = 0 for subsequent contiguous mouse commands.


Adding new commands to a script with a text editor

While creating a script starting with a record file, you may find that some commands that are absent from the initial script are needed, or that some commands should be changed. You could have QUANTA generate a new record file and generate a new script. Another option, which is perhaps the best way to learn the QUANTA syntax, is to use the QUANTA "command echo" option. When you use this feature, QUANTA reports in the text window the syntax of each command as it is executed.

To turn on command echoing, type:

For some commands, you may prefer to use keyboard commands that are never generated by the interface. For example, you can replace mouse movement commands with explicit movement commands such as ROT x 90 and TRAN y -10. For a summary of useful keyboard commands, see the Appendix on page 115.


Introduction to TCL Scripting Control

The real power of QUANTA scripts comes from TCL additions to QUANTA commands. These additions include variables, branching, lists, and subroutines.

All TCL commands in QUANTA must be preceded with the "!" character. All comments must contain an "*" in the first non-blank column.

Note: Keep in mind that QUANTA implements only a subset of TCL.

Please refer to Tool Command Language (TCL), for more information about TCL.


Variable definitions and usage.

Variables must be preceded by the "$" character when used (as opposed to being defined) in an expression:

TCL commands that return values are placed in square brackets:


Branching and looping

Note: Curly brackets create a statement block. Many TCL commands operate on lists. Lists will contain the characters "_list" in the variable's name for clarity. See Lists creation and modification on page 114.

FOREACH command:

FOR command:

IF/ELSE command:

WHILE command:

Below is a full TCL script that rotates a pre-saved scene (save the scene using File/Save Status):


Lists creation and modification

!list $val1 $val2 $val3

#returns a list

!glob -nocomplain  *.msf

#returns list of file names matching filter

!lappend shrt_list $item

#extend list short_list

List extraction

!lsearch $abig_list $str

#returns position in list of $str

!lindex  $my_list $index

#returns the specified entry in the list (from 0)

Operations

!expr $index+($val/2.0)

returns value+1

!incr $variable<optional inc. value>

increments variable

!string range $string $f $l

returns substring

!string tolower $str

converts to lowercase

!scan $string {%I %I} $val1 $val2

 

Input / Output

!echo "there are $numfiles files loaded"

 

!set $fileid [!open  myfile.txt <r|w|a>]

 

** note "fileid"contains a code returned by the open command that must be used in puts and read expressions.

!puts $fileid "There are [!llength $result] pairs."

#write a line to file

!set string  [!gets $fileid]	

#return next line from file to $string


Appendix


Commonly used QUANTA keyboard commands:

Note: QUANTA command keywords are not case sensitive. Uppercase signifies that it is required, but more characters are allowed.

SET ECHO ON

Turn on textport command echo

SET ECHO OFF

Turn off textport command echo

SCALE <scale>

Zoom in or out

ROTate <x|y|z> <angstrom value>	

Rotate view angle

TRANslate <x|y|z> <angstrom value>

Translate view

CLIP  <angstrom value>

set clipping plane width

MAP TAB SHOW     

Show the map table

MAP TAB HIDE     

Hide the map table

MAP ON 

Display active map

MAP OFF

Hide active map


TCL documentation

Please refer to Tool Command Language (TCL), for detailed information about TCL.


Sample TCL/rec scripts

See QUANTA Script Examples.


Binding commands to function keys

QUANTA commands can be bound to function keys on your workstation keyboard. Function keys F3 through F12 may be redefined. Either a single command or a pair of commands can be bound. In the former case, every time the function key is pressed, the command you have associated with the key is sent to the QUANTA command interpreter. In the latter case, the commands are sent alternately to allow toggling.

By default, function key bindings are defined by the file $HYD LIB/function key.dat. To view the default settings, open the Information menu in the menu bar. Select Current Session to open a pull-right menu and select Function Keys. The list of function key bindings is listed in the Textport.

You may print the PostScript file $HYD_LIB/funkey.ps to create a strip showing the default bindings to place above the function keys on your keyboard.

Complete the following exercise to familiarize yourself with the procedure for assigning customized key bindings.

1.   Define function key F5.

Open the Preferences menu in the menu bar. Select Device Settings to open the pull-right menu. Select Function Keys from the menu. A dialog box is displayed with a default number 3 in the data entry field.


Enter 5 in the field to select function key 5 as the key to be defined.


Click OK.


Another dialog box is displayed asking:

How should FK5 behave?

Select The Key acts the same each hit.

Click OK.


A third dialog box is displayed, requesting:

Enter the command this key will send.

In the data entry field, type:

Click OK.


You have defined key F5.

2.   Define function key F6.

When you complete the last step in defining F5, the dialog box for specifying the function key number to be defined is redisplayed with the number 5 as the default.

Enter 6 in the data entry field to select the function key to be defined.

Click OK.


The next dialog box is displayed, asking:

How should FK6 behave?

Select The Key acts the same each hit.

Click OK.


A third dialog box is displayed, requesting:

Enter the command this key will send.

In the data entry field, type:


The % denotes that the command is a palette selection.

Click OK.


You have defined key F6.

3.   Define function F7.

The dialog box for specifying the function key number to be defined is displayed, this time with the number 6 as the default.

Enter 7 in the data entry field to select the function key to be defined.

Click OK.


The next dialog box is displayed, asking:

How should FK7 behave?

Select The Key acts as a toggle.

Click OK.


A third dialog box is displayed, requesting:

Enter the command this key will send.

In the data entry field, type:


Click Return.


Another data entry dialog box is displayed.

Enter the alternate command:

Click OK.


4.   Save your changes to a local directory.

Finish the definition process.

Another dialog box is displayed.

Click Cancel.


A final dialog box is displayed with choices for saving the changes.

Click OK to accept the default: Save to Local Directory.



© 2006 Accelrys Software Inc.