Professional Documents
Culture Documents
Surpac v6.2
Table of Contents
Introduction ...................................................................................................................................... 6
Overview .................................................................................................................................................................. 6
Requirements........................................................................................................................................................... 6
Workflow ................................................................................................................................................................. 6
Page 4 of 81
Table of Contents
Page 5 of 81
Introduction
Overview
Gemcom Surpac provides tools that allow the software to be customised and many repetitive tasks
automated into a single control script. These control scripts tell the software to perform a series of
functions in an ordered manner. Control scripts are commonly called macros, Tcl scripts, or just simply
scripts.
The Surpac scripting language is an extension to an independent (non proprietary) scripting language
called Tcl. Tcl has been distributed freely since 1990 and is now used in thousands of applications worldwide.
The scripting engine (macro interpreter) contained within Surpac, processes scripts that may contain
standard Tcl statements along with Surpac extension commands called Scl. Tcl is an acronym for Tool
command language while Scl is an acronym for Surpac command language.
Requirements
This tutorial assumes that you have a basic knowledge of Surpac. If you are a new Surpac user, you
should go through the Introduction to Surpac manual before going through this manual. This manual
also assumes that you have basic skills in using a text editor such as CONText or Notepad. The tutorial
does not assume you have any previous scripting/programming background.
You will also need:
Workflow
Record
Script
Modify Script
Debug Script
Test Script
Complete Script
Note: This workflow demonstrates the steps in this tutorial. There are other ways to achieve a result.
Page 6 of 81
The name of the work directory is displayed in the title bar of the Surpac window.
Page 7 of 81
The name of the work directory is displayed in the title bar of the Surpac window.
Page 8 of 81
Logicals
Logicals
The name logical is a Surpac term that refers to the use of a known name that is used to map to a
physical directory. This known name, the logical, is mapped onto a directory on your hard disk at
runtime. Using this system the software does not have to refer to a hard coded directory name that is
possibly different on every installation of Surpac.
For example, the logical name SSI_ETC: (the known name) may be mapped to a directory named
c:/SurpacMinexSurpac_61/share/etc on one system or s:/software/Surpac/v6/share/etc on another.
Because the software uses the known name SSI_ETC: to refer to the directory it does not need to know
where this directory actually exists as it is mapped at runtime.
The reasons logicals are used can be summarised as:
Data standardisation
Personal defined in any file and specified to Surpac via the Customise > Default Preferences
command
Page 9 of 81
Logicals
System logicals are defined by the software install procedure and are stored into a file that is usually
called translate.ssi. The system logicals are mandatory for the successful operation of the software. You
should never have to modify a system logical. Below is an example translate file.
MACHINE=WIN32
SSI_ETC:
SSI_STYLES:
SSI_PLOTTING:
SSI_PROFILES:
SSI_HMF:
SSI_MESSAGES:
SSI_REFMAN:
SSI_RESOURCE:
SSI_JAVA:
SSI_BIN:
SSI_LIB:
END
TIP:
Never add user logicals to the translate file. This is because at each new installation of the software this file will
be recreated and so you will loose any changes that you had made.
User logicals are optional and are used to make your life easier. Just as system logicals make it easy for
the software to locate files, user logicals make it easy for you to locate your data and macros. You could
define logicals to centralise the storage of your survey pickups on site. You could make a repository for all
macros and scripts to be stored so each user on site has access to them via a consistent name such as
MACRO: .
Logicals allow you to access data via a standardised naming convention, without having to worry about
the physical location of files on a disk. When working in a network environment this can be a benefit,
especially when users have different physical drive mappings.
User logicals are also an invaluable tool when designing menu systems and Tcl/Scl scripts. By using
logicals, the menu definitions and macro scripts can be kept insulated from the file system as there is no
need to worry about physical drive mappings. This way when menus and scripts are transferred to other
computers, it is only the logical reference in the logicals.ssi file that needs to be changed and not the
actual script or menu definitions.
User logicals are defined in a file called logicals.ssi that resides in the SSI_ETC: directory (this is a
system logical that maps to the directory where the etc files are stored). The logicals.ssi file is optional, if
it does not exist Surpac will not report an error, however if it is present then Surpac will load the file and
add any defined logicals to the system logical map.
Personal logicals are similar to user logicals except that they can be defined in a file called anything you
like such as mylogicals.txt . To make Surpac load a personal logicals file you must define it to the
software via the alias tab of the default preferences option from the customise menu. The format of a
personal alias file is exactly the same as the logicals.ssi file.
When Surpac starts, it will load logical definitions in the following order:
1. System logicals from SSI_ETC:translate.ssi
2. User logicals from SSI_ETC:logicals.ssi
3. Personal logicals from your defined logical file
Page 10 of 81
Logicals
If there are duplicate logical definitions then the last one read is the one that takes precedence. It is not
an error to define duplicate logicals and there may be good reasons to do so, such as redefining the
location of the SSI_PLOTTING: logical in your personal logicals file.
Below is an example of a logicals.ssi file or a personal logicals file.
MINESOLUTIONS:
MS_SPOOLER:
MS_STRING:
MS_RINGKING:
MY_MACROS:
c:/minesolutions/
c:/minesolutions/spooler/
c:/minesolutions/string/
c:/minesolutions/ringking/
c:/macros/
The structure of the file is quite basic. Simply define the logical name, leave some white space (one or
more spaces) and then define the physical directory mapping followed by a trailing slash.
Note:
Tips:
Use of the full colon that appears at the end of each logical is a style issue that you are urged to adopt. It
provides a consistent end of logical marker and makes file paths easier to read when using logicals.
Forward slashes are recommended over backslashes for your physical paths. Backslashes tend to sometimes
causes obscure problems due to their escaping function in Tcl scripts.
Make sure your physical directory names are correct as Surpac makes no check to see if they actually exist.
Page 11 of 81
Command Alias
3.
The pathname of the current work directory is display in the title bar of the Surpac window.
Define a logical called MY_WORK: that will map to the current work directory. Your definition would look
similar to the following extract from the default.ssi file:
4. In CONText choose File > Save As and save the file into the SSI_ETC: directory and call it
logicals.ssi.
5. If you are running Surpac, exit and then restart.
6. Now locate your new logical called MY_WORK: in the file navigator.
Note:
Tip:
All logical names are listed in the Surpac Navigator beneath the folder names in alphabetical order.
If your logical called MY_WORK: cannot be found in the list check that you have named the logicals file correctly
as described in step 4. Make sure you know what the actual pathname for SSI_ETC is. You can verify this by
finding the SSI_ETC logical in the Surpac File Navigator and expanding it.
Command Alias
A command alias is a system that provides a mechanism for you to rename commands in Surpac to
something that you find more suitable or easier to remember. It is often quicker for experienced software
users to make use of these short cut alias names than it is to type the full command name or find the
function on a menu or toolbar.
Command aliases are defined in a text file with a set syntax. Firstly, the alias name is given which is
enclosed in double quotes, followed by any amount of white space and then the actual command name
(or even a previously defined alias) enclosed in double quotes. An extract from the distributed short.mst
alias file follows:
"2DG"
"2DT"
"3DG"
"3DT"
"ATP"
"AR"
"AB"
"AII"
"AD"
"BS"
"BD"
"BR"
Tip:
"2D GRID"
"2D TRANSFORM"
"3D GRID"
"3D TRANSFORMATION"
"ADD TO PERIOD"
"ADD RIG"
"APPLY BOUNDARY"
"ARC ARC INTERSECT"
"AUDIT DATABASE"
"BASIC STATISTICS"
"BEARING AND DISTANCE"
"BENCH REPORT"
When defining alias names that clash, the last one the software reads is the one that takes precedence. Surpac
does not warn you of duplicate names so beware.
Page 12 of 81
Command Alias
As well as allowing you to rename existing commands, the alias system also allows you to define new
commands that you can associate with your Tcl/Scl scripts. For example, say you have defined two
scripts, one to import a csv file and load into a database table, and another to export a database table to
a csv file. Later we will cover how to attach these two scripts to menus but it is also feasible to make
keyboard commands for them. The following alias file defines two new commands import_csv and
export_csv to do this.
"IMPORT_CSV"
"EXPORT_CSV"
MACRO:MY_WORK:IMPORT_CSV"
MACRO:MY_WORK:EXPORT_CSV"
Note the use of the keyword MACRO: above. This keyword tells the software that it is not mapping to an
internal Surpac command but instead is going to run Tcl script that is stored on the hard disk. Notice the
use of the logical MY_SCRIPTS: which will map to the actual directory path where the macro is stored.
This logical is assumed to be previously defined in logicals.ssi.
Surpac allows you to specify up to nine alias files.
To define an alias file to the software, choose Customise > Default Preference, select the Alias files
folder and enter the name of your alias file including any logical or physical directory name.
Page 13 of 81
Command Alias
Note:
Make sure you type exactly as shown, taking care with upper and lower case letters.
3. In the Context editor, choose File > Save As and save the file as hello.tcl into the current work
directory.
4. In the Context editor, choose File > New.
5. Now create a new command alias called HELLO that will run the script created in steps 2 & 3.
Your alias definition in the editor should look as follows:
6. Now create a new command alias definition called HELLO that will run the script created in steps
2 and 3. Your alias definition in the editor should look as follows:
HELLO
Note:
MACRO:MY_WORK:hello.tcl
The MY_WORK: section is the logical name created in the previous task. Using the logical name as part of the
alias definition means that the command will work from any directory otherwise it only works if the current work
directory is where the macro is created in.
7. In the Context editor, choose File > Save As and call the file myCommands.txt.
8. In Surpac, choose Customise > Default preferences. Then enter the full pathname to the alias
file you have created in steps 6 & 7.
9. Exit Surpac and then restart.
10. Type HELLO at the command prompt in Surpac. You should see the following output in the
message window:
Hello Surpac - this is my first script
Tip:
When defining alias commands to run scripts it is safer to make use of logicals as in the example above.
Page 14 of 81
Keymaps
Keymaps
The keymaps file is largely a historical file used in earlier versions of the software to map the keyboard
keys to characters. In Surpac, the only real purpose of the file is to define actions associated with the
function keys. You can define your own hotkeys to run scripts that you have written.
Using the csv example from the alias discussion above, the keymaps.ssi file extract shows how to define
hot keys on the F7 and F8 keys to run the import/export csv scripts.
"f7"
"f8"
Tip:
FUNCTION
FUNCTION
"MACRO:MY_SCRIPTS:IMPORT_CSV"
"MACRO:MY_SCRIPTS:EXPORT_CSV"
When defining hot keys the key name must be in lowercase characters (ie f10 not F10).
This task assumes you performed the task outlined under the Command Alias section.
1. In the CONText editor choose File > Open and open SSI_ETC:keymaps.ssi.
2. Locate the section that defines the F1 through F10 keys by scrolling down a little.
3. Define a hotkey F11 to run the hello.tcl script by inserting a new line as follows:
f11
Note:
FUNCTION
MACRO:MY_WORK:hello.tcl
The MY_WORK: section is the logical name created in the previous task. Using the logical name as part of the
alias definition means that the command will work from any directory otherwise it only works if the current work
directory is where the macro is created in.
Page 15 of 81
Page 16 of 81
The process of creating menus can be done entirely through Surpac and requires no manual editing of
text files. The first time this function is invoked in a session it can take several seconds before the editor
tool is displayed. This is because all available menus and toolbars are read so they are available in the
editor.
You can attach any existing menu tree to it using the copy and paste buttons of the editor tool. These three
functions are also available from the click right popup menu.
Page 17 of 81
3. To populate it with menu items, highlight it and define a new menu item beneath it by selecting
the new button.
You can then attach any number of menu items to it, including other sub menus. When defining new
menu items, the following Create Menu Item form is displayed.
Description
Item Category
Label
Type
Command
Either the name of the internal Surpac function, or the full path name to the Tcl script.
Note that you should never use physical paths but instead use a logical name
Image
A 20x20 pixel gif image that will appear as part of the menu label
You can attach any existing toolbar button to you toolbar using the copy and paste buttons of the editor tool.
Note that you can only paste toolbar buttons to the actual toolbar. Toolbars are not hierarchical like menus.
Page 18 of 81
2. Fill in the Create Toolbar Item form, and then click Apply.
The toolbar button fields are:
Input
Description
Item Category
Type
Command
Either the name of the internal Surpac function, or the full path name to the Tcl script.
Note that you should never use physical paths but instead use a logical name
Image
A 20x20 pixel gif image that will appear as part of the menu label
Tool Tip
Tips:
Icons that you link in with your buttons via the Image item are optimal at 20X20 pixel icon. This is the standard
for Surpac toolbar icons.
Toolbar buttons are far more effective when there is an associated ToolTip that will be displayed when the
mouse pointer is positioned over the button.
Page 19 of 81
Macro Record
Macro Record
The act of recording a series of steps that you perform in the software is a very simple operation. You
need to signal to Surpac that you want to record everything you do in the software until you again signal
to the software to stop recording your actions.
2. Enter the name of a script file in which to record your actions. After assigning a name to your
macro script you simply use the software as normal to perform your desired tasks.
3. When you have completed the tasks that you want to record complete the record operation by
depressing the macro record button
Note:
A message to indicate that the recording process has finished appears in the message window.
Page 20 of 81
Macro Playback
Macro Playback
Task: Playback the Macro
Once you have recorded your tasks, the next thing that you want to do is play them back.
1. Press the playback button on the toolbar
or press F6 on the keyboard. The Macro Playback
dialogue is presented where you enter the name of the script you wish to playback.
Note:
The parameters 1 to 10 fields above are provided for backward compatibility with the superseded V3.2 macro
language.
Drag and drop the script file hello.tcl from the Navigator into graphics.
or
Page 21 of 81
######################################################################
#
# Macro Name
: c:/vcomp/training/gettingstarted/v61/example03_01.tcl
#
# Version
: Surpac 6.1
#
# Creation Date : Tue Mar 04 21:11:28 2008
#
# Description
:
#
######################################################################
set status [ SclFunction "CREATE DTM" {
frm00126={
{
location="DATA:pit"
break="Y"
bdyloc=""
interpolate_new_points="N"
bdystr="1"
spotrng=""
id="1"
check_distance="0.0050"
anyspots="N"
swadesc="Y"
bdyid="0"
inout="I"
brktest="Y"
apply_boundary="N"
interpolate_new_points_distance="50"
}
}
}]
A recorded macro will always contain a header block at the top. This section of the script is non-functional
but describes the script name, version of Surpac that created it and the date recorded. There is also a
section for a description of the script. It is good practice to insert some comments on the use of the
macro so if you or someone else is ever required to modify the macro later you will know what the
purpose of it was.
The header block makes use of the Tcl comment character hash (#). If the first non-blank character on
the line is a hash then the Tcl interpreter ignores everything afterwards. It is also good practice to include
comments through your script to describe what is happening at different points. This is especially true for
large macros.
Page 22 of 81
Following the header block are the actual functions that you performed while recording the macro. The
example above shows how a Surpac function is recorded making use of the Scl extension command
SclFunction.
The SclFunction command takes two parameters, the Surpac function name and then any extra
information that is required by that particular function grouped by curly braces. A function that includes
interaction with a form will always be recorded with the form identifier (i.e. frm00236) followed by a list of
the fields on the form and their entered values.
Not all Surpac functions interact with the user via forms. Some functions do not require any further input
such as the ZOOM ALL function shown below.
######################################################################
#
# Macro Name
: c:/vcomp/training/gettingstarted/v61/example03_02.tcl
#
# Version
: Surpac 6.1
#
# Creation Date : Tue Mar 04 21:31:58 2008
#
# Description
:
#
######################################################################
set status [ SclFunction "ZOOM ALL" {} ]
Other functions are graphical in nature and require input via the mouse pointer. The IDENTIFY POINT
function shown below is one such function.
######################################################################
#
# Macro Name
: c:/vcomp/training/gettingstarted/v61/example03_03.tcl
#
# Version
: Surpac 6.1
#
# Creation Date : Tue Mar 04 21:32:42 2008
#
# Description
:
#
######################################################################
set status [ SclFunction "IDENTIFY POINT" {
select_point={
{
winx="-0.036"
winy="0.113"
objectx="2427.152"
objecty="6940.296"
objectz="951.362"
}
}
}]
Page 23 of 81
When a graphical function is recorded that consists of more than one point selection the format alters a
little from the previous example. The example below shows how the BEARING AND DISTANCE function
records the selected points in a tabular format into the macro.
######################################################################
#
# Macro Name
: c:/vcomp/training/gettingstarted/v61/example03_04.tcl
#
# Version
: Surpac 6.1
#
# Creation Date : Tue Mar 04 21:33:33 2008
#
# Description
:
#
######################################################################
set status [ SclFunction "BEARING AND DISTANCE" {
select_point=table { winx winy objectx objecty objectz } {
{ "-0.309" "-0.016" "2334.868" "6908.197" "1058.790" }
{ "0.448" "-0.048" "2590.321" "6900.172" "1048.291" }
}
}]
A new style of Surpac function has been introduced that does not contain the traditional form structure of
pre version 6 functions. These new style functions appear as shown below where a OPEN FILE function
has been recorded.
######################################################################
#
# Macro Name
: c:/vcomp/training/gettingstarted/v61/example03_05.tcl
#
# Version
: Surpac 6.1
#
# Creation Date : Tue Mar 04 21:36:56 2008
#
# Description
:
#
######################################################################
set status [ SclFunction "OPEN FILE" {
layer="main graphics layer"
location="DATA:pit1.str"
plugin="Surpac String Files"
Surpac={
IDRange=""
range=""
descriptions="true"
}
styles="SSI_STYLES:styles.ssi"
replace="true"
rescale="true"
}]
Page 24 of 81
SclFunction
SclFunction
The SclFunction command is a Surpac extension that provides the mechanics of invoking a function
from within your script. A call to the SclFunction command is recorded automatically by Surpac and it
would be unusual that you would ever hand code one.
Syntax
SclFunction FunctionName FunctionParameters
Where
FunctionName is the name of the Surpac function to execute enclosed in double quotes
FunctionParameters are any further information that the Surpac function requires to run enclosed
in curly braces
Return Values
Returns either the Scl constant SCL_OK or SCL_ERROR depending upon success or failure of
the function to run correctly
The function returns a value when, as coded above will be stored in a variable called status. The status
variable can then be checked for success or failure. A later chapter will provide the skills to do this.
Note:
When recording macros, movements you perform with the mouse are not recorded! The graphics viewer does
not interface with the macro system which handles rotating data via the mouse. If you want to rotate data in your
macro script, you can use the following functions that are available off the Rotate image submenu of the View
menu
Orbit up
Orbit down
Orbit left
Orbit right
Roll left
Roll right
Page 25 of 81
_action="display"
_action="apply"
Notes: The double quotes surrounding the keywords to the right of the equal sign are significant.
With new style functions such as OPEN FILE, the _action switch has no effect.
The display setting will show the form and allow the user to interact with it, while the apply setting will
automatically apply the form without displaying it.
Another feature of the SclFunction command is all form fields that have not been included in the
nd
parameter section (2 argument) will take on default values rather than cause an error. This means that if
new fields are added to a form in a future release of Surpac, your macro will continue to work.
Page 26 of 81
{
_action="apply"
location="DATA:pit"
id="1"
}
}
}]
The example above will set the location and id fields of CREATE DTM and automatically apply the form
using default values for the other fields.
Page 27 of 81
6. Now edit the script in Context and insert an _action=display switch and then replay the script.
Notice the Create DTM form now displays and allows you to change the string file name that you
used when you recorded the script.
7. Edit the script in Context again and remove lines so that it appears as in the code snippet above.
Replay the script again to see if it still works.
Often you will want to be able to select points graphically when you are running a macro. For example
this could be to inspect the properties of a point using the IDENTIFY POINT function. The
_action=display switch can be used to achieve this as is shown in the example below.
Page 28 of 81
What is Tcl?
What is Tcl?
Tcl is two things, firstly a scripting language, and secondly an interpreter. As a scripting language, Tcl
provides us with a standard syntax, variables, flow control, and procedures. It is an extensible language
that allows third parties to add their own functionality.
As an interpreter, Tcl can be easily embedded into an application such as Surpac. Many other software
vendors worldwide have also adopted Tcl as an embedded scripting language. The function of the
interpreter is to process scripts line by line to produce a result.
Tcl is public domain software that is freely available and can be used in commercial applications. It is
available on a number of platforms including Windows NT/98/2000, Unix varieties, and Macintosh.
What is Scl?
Scl commands are extensions to the Tcl interpreter that allow you great flexibility in your scripts to
manipulate both the externals and internals of Surpac. Through Scl commands, you can:
insert, modify and delete point and triangle data within graphics layers
All these tools allow you to create new applications within Surpac that appear as if they are intrinsic
Surpac functions.
Although there are a number of Scl commands at your disposal, it is typical that you will only ever use a
small subset of them. To inspect the Scl command documentation, invoke the help browser on the
Surpac contents page and then click the link to SCL.
Page 29 of 81
Tcl Syntax
Tcl Syntax
The language syntax employed by Tcl is quite simple.
Syntax
command parameter1 parameter2
Where
Command is the name of a Tcl internal command or defined procedure
Parameter1 and subsequent parameters are optional depending upon the requirements of
command
Commands and parameters are separated by white space. The end of line signifies the end of the
commands arguments, unless a backslash character is used to continue the command over onto the
next line. Comments in Tcl can be inserted by using the # symbol as the first non white space character
on a line.
Commands
Everything that causes the Tcl interpreter to do something is a command. Each new line in a tcl script
begins with a command. Commands may have optional parameters as defined by the specified
command.
Two commands that you will use frequently are the set and put commands.
set
The set command is used to create variables in your script. A variable is simply a named location in
memory used to store information. Think of a variable as a bucket that contains something (information)
with a label on the front (its name) that you can use to identify it from other buckets. The syntax for set is
Syntax
set varName value
Where
varName is the name you want to call the variable
value is the assigned value to the variable
Examples
set tableName assay
set dip 49.5
set sectionName temp_sec
Page 30 of 81
puts
The puts command is used to print messages to the message window. It takes one argument, which is
the message to print. puts stands for put string but it may be easier to think of it as simply print.
Syntax
puts message
Where
message is the text and/or variables to print
Example
puts Hello Surpac user
puts The DB table being reported is $tableName
Page 31 of 81
Grouping Constructs
Grouping Constructs
The previous example exposed the first grouping construct. Double quotes are used to group string
tokens together and have them treated as one autonomous object.
The puts command (as used previously) expects one argument, that being some text to write to the
message window. If the double quotes were not used in the previous example then puts would be given
six parameters because white space is used to separate parameters.
The other grouping construct used in Tcl is curly braces. The difference between curly braces and double
quotes as grouping constructs is that double quotes permit variable substitution and further command
processing and curly braces do not.
If we change the puts example to use curly braces then
set sectionNumber 6800
puts {The current section is $sectionNumber}
Will result in the following output to the message window
The current section is $sectionNumber
Command Substitution
Only the first token encountered on a line is treated as a Tcl command. Sometimes it is necessary to
execute another Tcl command as part of an original Tcl command. This will become apparent as you
progress through this tutorial.
To execute a command as part of another command you enclose the secondary command in square
brackets []. Whenever you want to get the result of a command and use it as a parameter to another
command you use square brackets.
set drillholeId rc0001
puts Drill Hole ID = [string toupper $drillholeid]
This will result in the message below being printed to the message window.
Drill Hole ID = RC0001
Note:
The string toupper command as used in the above example will be explained in a later topic.
Another example:
set number 100
set new_number [expr $number * 10]
puts The new number is $new_number
This will result in the message below being printed to the message window.
The new number is 1000
Note:
The expr command as used in the above example will be explained in a later unit.
Page 32 of 81
Guido
Guido
Guido is an acronym for Graphical User Interface Design Objects. The Guido commands are Surpac
extensions to the Tcl interpreter. The various Guido tools are provided so you can write forms to interact
with the user in order to get information to use in your script.
There are two type of GUIDO commands, Guido container objects and Guido widgets. A Guido container
is an object that contains other Guido objects that may be containers or widgets. A container object is
used to organise the layout and appearance of your form. A Guido widget is an object that is used to
retrieve information from a user.
Some common Guido container and widget objects
Guido Containers
Guido Widgets
GuidoForm
GuidoField
GuidoPanel
GuidoComboBox
GuidoScrollPane
GuidoCheckBox
GuidoTable
GuidoRadioButton
GuidoTabbedPane
GuidoButtonGroupPanel
GuidoFileBrowserField
Page 33 of 81
Syntax
GuidoCommand name commandBody
Where
GuidoCommand is the name of the actual Guido command.
name is your assigned name for the Guido command (like a variable name). This name will be
used to reference it later to retrieve data that is entered into it.
commandBody is enclosed in braces and will contain all switches used to define the look of the
Guido widget or container on the form. In the case of a Guido container other Guido commands will
also be contained within these braces.
Description
-label
-width
-height
-default
-format
-high_bound
-low_bound
-null
-translate
-input
-dependency
Note:
See the online documentation for a full list of all available switches and example usage.
Page 34 of 81
GuidoForm
GuidoForm
The GuidoForm command is used to define a form that will contain any number of widgets and
containers. GuidoForms have some special switches which are:
Switch
Description
-default_buttons
Place the standard Apply, Cancel and Help buttons on the form
-defaults_key <name>
Example
GuidoForm form {
-label An Example Form
-default_buttons
-defaults_key abc_mines
# insert other guido objects here
}
SclCreateGuidoForm
The SclCreateGuidoForm function will turn a Guido form definition into a computer representation in
memory such that it is ready to be displayed on the screen. Its syntax is:
Syntax
SclCreateGuidoForm FormHandle FormDefinition Body
Where
FormHandle is a named variable that you use to reference the created form with.
FormDefinition is the form definition is usually the variable name that contains the actual form
definition.
(i.e. $myForm). It can also be the name of an external file that contains the definition prefixed with
the @ sign (i.e. @section_form.tcl).
Body is the command body. It can contain statements to set default values for form fields. It is
usually a pair of curly braces {}.
Return Values
SCL_OK if the function creates the form object with no error
SCL_ERROR if something goes wrong
Example
An example that will create a form from the definition stored in a Tcl variable named sectionForm.
SclCreateGuidoForm form_handle $section_form {}
An example that will create a form from the definition stored within a file called gradecontrol.frm.
SclCreateGuidoForm form_handle @gradecontrol.frm {}
Page 35 of 81
SclRun
SclRun
The SclRun command will display and execute a Guido form that has previously been created with the
SclCreateGuidoFormCommand. Its syntax is:
Syntax
FormHandle SclRun Body
Where
FormHandle is the named variable that you use to reference the form created with the
SclCreateGuidoForm command.
Body is the command body can contain extra statements. It is usually a pair of curly braces {}.
Return Values
SCL_OK if the function creates the form object with no error
SCL_ERROR if something goes wrong
Example
$section_form SclRun {}
The SclRun command creates a Tcl variable for each Guido widget defined on the form except if the
cancel button is pressed. The variables created use the same name as was defined for each Guido
widget in the form definition.
A special variable with the name _status is also created and it is assigned a character string that
represents the button that was pressed to dismiss the form. For example, if the Apply button is pressed
then this variable is assigned the value apply, while if the Cancel button is pressed this variable is
assigned the value cancel.
The following example code segment allows you to test to see if the user pressed cancel, and if so exit
the script gracefully.
$grade_control_form SclRun {}
if {$_status == cancel} {
return
}
Note:
Page 36 of 81
set form_def {
GuidoForm form {
-label "My First Form"
-default_buttons
-defaults_key my_form
}
}
SclCreateGuidoForm form_handle $form_def {}
$form_handle SclRun {}
Note:
The actual form definition is stored into a Tcl variable called form_def. This is the usual way to define a form but
they can also be defined in external files and then specified to the SclCreateGuidoForm command via the @
character. The following example shows how to create a form from a definition stored into called my_form.tcl.
2. Save the file and then run the script in Surpac to display your first form. It should look as follows:
Page 37 of 81
GuidoField
GuidoField
A GuidoField is the most common Guido widget you will use. It will accept input that the user will type at
the keyboard. It can contain all the various switches described previously to setup labels, field widths, and
validation criteria.
set form_def {
GuidoForm form {
-label "GuidoField Form"
-default_buttons
GuidoField number {
-label "Enter a real number"
-format double
-width 10
-low_bound 0
-high_bound 100
-null false
}
}
}
SclCreateGuidoForm form_handle $form_def {}
$form_handle SclRun {}
puts The number is $number
2. Save the script and then run it. A form as shown below appears.
3. Now try to enter a number into the field that is not within the range 0 to 100 and press Apply.
Notice that the form will not apply if the number does not fit the validation criteria that were set in
the definition.
4. Finally enter a number between 0 and 100 and then press Apply. The final line in the script prints
the value to the message window. Notice that the variable name used in the puts statement
(number) is exactly the same as the name assigned to the GuidoField in the definition.
Page 38 of 81
GuidoComboBox
GuidoComboBox
A GuidoComboBox is similar to a field except that you can provide a set of values for the user to select
that will appear in a drop down list. GuidoComboBoxes can be exclusive or non exclusive. Exclusive
comboboxes only permit an entry from the list, while with non exclusive combo boxes any value can be
entered as long as it meets any validation criteria set.
Any of the switches described previously may be used on a GuidoComboBox. There are also some
special switches that can only be used with combo boxes.
Switch
Description
-exclusive
If set to true will only allow values to be selected from the list otherwise
any text can be entered
-value_in
2. Save the script and then run it. A form as shown below appears.
3. Now try to enter a value that was not in the list and press Apply.
Page 39 of 81
GuidoCheckBox
GuidoCheckBox
A GuidoCheckBox is a widget that is used to select one of two possible states, such as yes/no, on/off
up/down, etc. When the check box is selected it will return the text true and when unselected it will return
the text false. These default values can be changed using the switches below:
Switch
Description
-caption
-caption_placement
-selected_value
-unselected_value
2. Save the script and the run it. A form as shown below appears.
3. Notice that when you press Apply the value yes or no is printed. This is because these values
were set with the selected and unselected value switches.
Tip:
When defining check boxes specifying height 1 will make them line up correctly with their label.
Page 40 of 81
Switch
Description
-caption
-caption_placement
-selected_value
-unselected_value
The real power of radio buttons is that they can be combined together within a
GuidoButtonGroupPanel. When they are combined only one of the buttons defined within the group
maybe selected at any time, like an old fashioned car radio.
A button group panel is a chameleon object in that it is both a container and a widget. Its value will
become that of the selected radio button within it once the form is applied.
GuidoFileBrowserField
2. Save the script and then run it. A form as shown below appears.
3. Notice that only one button can be selected at any time. Also take note of the print statement at
the end. In the puts statement, the name of the GuidoButtonGroup is used to retrieve the entered
value.
Tip:
When defining radio buttons specifying height 1 will make them line up correctly with their label.
GuidoFileBrowserField
A GuidoFileBrowserField is a special purpose widget that is used to get valid filenames from the user. It
appears like a combo box except that a file chooser widget is invoked when the triangle icon is selected.
There are a number of switches associated with file browsers.
Switch
Description
-file_access
Specify the access of the selected file. Can be read | write | exist
-file_mask
-start_dir
-multiple_selection
Specify that you wish to selected more than one filename in the
browser
-link
Link this field to another field that will contain the id part of the filename
when using location and ids
-extension
Specify if you want the file extension trimmed off the return name. Can
be true | false
Page 42 of 81
GuidoLabel
2. Save the script and then run it. A form as shown below appears.
GuidoLabel
A GuidoLabel is not a true widget as such but it is best described here. A GuidoLabel is used to put a
text or informational messages onto your form to help users understand your macro.
Page 43 of 81
Dependencies in Guido
2. Save the script and then run it. A form as shown below is displayed.
Dependencies in Guido
Any Guido object may contain a dependency switch. A dependency will make a particular widget or
container dependent upon the value of another widget on the form. The effect of a dependency is to turn
the dependant object on or off. When Guido Widgets are turned off (ie their dependency condition is
false) they appear greyed out. When GuidoPanels are turned off they become invisible as does
everything that is contained within them.
Page 44 of 81
Dependencies in Guido
2. Save the script and then run it. A form as shown below is displayed.
3. Notice that when you select the check box the radio buttons for plot size will appear as normal.
Page 45 of 81
Dependencies in Guido
2.
Page 46 of 81
Dependencies in Guido
3.
4.
5.
Edit the recorded adjust_cords.tcl script and add the Guido code necessary to produce the form
displayed below. The form should use variable names for each field as follows:
in_location
in_id
out_location
adjust_x
adjust_y
adjust_z
Note that all fields should have appropriate validation settings for format and nulls. The input location is a
file browser field linked to the id. Inserting the following form definition code at line 1 of the script, prior to
the recorded section, will produce this form.
Page 47 of 81
Dependencies in Guido
set adjustCoordsForm {
GuidoForm adjustCoordsForm {
-label "Adjust Coordinates"
-default_buttons
GuidoFileBrowserField in_location {
-label "Input location"
-width 20
-format none
-null false
-extension "*.str"
-link inId
}
GuidoField in_id {
-label "Id"
-format float
-null false
}
GuidoField out_location {
-label "Output location"
-width 20
-format none
-null false
}
GuidoField adjust_x {
-label "Adjust X"
-format float
-null false
-default 0
}
GuidoField adjust_y {
-label "Adjust Y"
-format float
-null false
-default 0
}
GuidoField adjust_z {
-label "Adjust Z"
-format float
-null false
-default 0
}
}
}
# create and display the form
SclCreateGuidoForm adjustCoordsFormHandle $adjustCoordsForm
{}
$adjustCoordsFormHandle SclRun {}
Page 48 of 81
Dependencies in Guido
The final step is to remove the hard coded values as were saved into the SclFunction when the macro
was recorded and replace them with the variables as coded on the GuidoForm above.
6.
Edit the macro again and modify the SclFunction statement to look as follows:
7.
Finally, save the macro and then run and test it to ensure it functions correctly.
Note:
To test the completed macro simply recall your original string file into graphics and then recall the newly created
file. You should see that the new file is shifted by the delta values that you entered on your form
Page 49 of 81
Syntax
SclSelectPoint handle prompt layer stringNo segNo pointNo x y z desc
Where
Handle is a returned reference variable that can be used to modify the selected point using other
Scl extension functions (not covered in this tutorial)
Prompt is any text that you want to appear on the screen to signal to the user to select something
Layer is a variable into which the layer name of the selected point is returned
stringNo is a variable into which the string number of the selected point is returned
segNo is a variable into which the segment number of the selected point is returned
pntNo is a variable into which the point number of the selected point is returned
x y z are variables into which the x, y, and z coordinates of the selected point are returned
desc is a variable into which the entire description field of the selected point is returned
Return Values
Returns either the Scl constant SCL_OK or SCL_ERROR depending upon success or failure of
the function to run correctly
Note:
The backslash used on line 1 of the above example is used as a continuation character to extend line 1 onto line
2. In your example you can combine lines 1 & 2 onto the same line
Page 50 of 81
Task: Use SclSelectPoint and Then Pass xyz Values Back to Surpac
1.
Open pit1.str.
2.
3.
Choose Inquire > Bearing and distance between two points, perform one bearing and distance
function and then press Escape.
4.
5.
Play the macro back. Notice that it performs the same bearing and distance and then exits.
6.
Edit the script so that it now uses the _action=display technique to allow any points to be
selected in graphics.
Note:
7.
Play the macro back again. Notice that although you can select any points now the script sits in
graphics selection cycle instead of exiting.
Page 51 of 81
8.
Note:
9.
The backslashes used the above example is used as a continuation character to extend a line onto the next line
2. In your example you can combine these lines together
Play the script back. Notice this time that you get to select two points, then the bearing and
distance function is run and the script then completes
Page 52 of 81
The first format adds one to the value stored in variableName while the second format will add the
specified number to the value stored in variableName.
Page 53 of 81
2. Now run Task08_1.tcl and inspect the results. They should appear as follows:
1
1100
90
Meaning
* / %
+ -
Add, Subtract
Heading
Heading
Heading
Heading
acos
cos
Hypot
sinh
asin
cosh
Log
sqrt
atan
exp
log10
tan
atan2
floor
Pow
tanh
ceil
fmod
Sin
Page 54 of 81
The Tcl expr command also supports the following conversion functions:
Heading
Heading
abs(arg)
Returns the absolute value of arg. Arg may be either integer or floating-point, and the result
is returned in the same form
double(arg)
If arg is a floating value, returns arg, otherwise converts arg to floating and returns the
converted value.
int(arg)
If arg is an integer value, returns arg, otherwise converts arg to integer by truncation and
returns the converted value.
rand()
Returns a floating point number from zero to just less than one or, in mathematical terms,
the range [0,1). The seed comes from the internal clock of the machine or may be set
manual with the srand function.
round(arg)
If arg is an integer value, returns arg, otherwise converts arg to integer by rounding and
returns the converted value.
srand(arg)
The arg, which must be an integer, is used to reset the seed for the random number
generator. Returns the first random number from that seed.
x1
y1
x2
y2
1000
1000
2000
2000
-1000
1000
1414.21356237
Page 55 of 81
boolean functions
bitwise functions
algebraic functions
string functions
exponential functions
conversion functions
datetime functions
miscellaneous functions
[SclExpr RTOD($rad)]
Page 56 of 81
string length
string index
string first
string range
string trim
string tolower
string toupper
2. Now run Task08_4.tcl and inspect the results, they should appear as below
13
end - the keyword end refers to the last character of the string.
Page 57 of 81
2. Now run Task08_5.tcl and inspect the results, they should appear as below
3
8
2. Now run Task08_6.tcl and inspect the results. , they should appear as below
2
9
Page 58 of 81
2. Now run Task08_7.tcl and inspect the results. They should appear as below.
123
789
2. Now run Task08_8.tcl and inspect the results, they should appear as below
456
456
2. Now run Task08_9.tcl and inspect the results, they should appear as below
ore grade
ORE GRADE
Page 59 of 81
2. Now run Task08_10.tcl. Check the current directory, there should be a new1.str and a new2.str
file present.
2. Now run Task08_11.tcl and inspect the results. The two files created in the previous task should
now be deleted when you check the current directory
2. Now run Task08_12.tcl , there should now be a new files called oldone.str in the current
directory
Page 60 of 81
2. Now run Task08_13.tcl and inspect the results, they should appear as below.
Processing file ...
2. Now run Task08_14.tcl and inspect the results, they should appear as below
in temp
removed temp
Page 61 of 81
This task will read all *.tmp and *.cf files in the current directory and load them into a list variable called fileList.
The foreach loop will then loop over each file in the list storing them one by one into the variable fileName at
each loop iteration. The file delete command deletes the files one by one as the loop iterates.
Page 62 of 81
Boolean Expressions
Boolean Expressions
Flow control constructs such as branching to a section of code or repeating a number of commands are
based upon some conditional test. As an example in English you could say:
Notice the keywords if and then; they describe some action. The user selected to plot is the condition or
test criteria which determines if the plotting code is executed. This condition can evaluate to only true or
false. Another example:
In this example while and continue are the action words. The is another section number is the condition
or test that determines if we can continue extracting sections. Again, this test can only evaluate to true or
false.
A Boolean expression is simply an expression that can result in one of two possible outcomes that are
true or false. They are based on testing something, whether it be comparing simple numbers or text
strings or some complicated arithmetic expression, and even combinations of both.
When you code a Boolean expression it is best to sound out what you are trying to test for in English as
in the above examples. It can assist you in getting your logic correct.
The table that follows lists the more common operators that you will use when creating Boolean
expressions to make choices in your macros. The operators are grouped in decreasing order of
precedence.
Operator
Example
Description
!$a
Logical NOT;
Negate the value on the left hand side
i.e. while not at the end of file
<
$a < $b
>
$a > $b
<=
$a <= $b
Operator
Boolean Expressions
Example
Description
Is the value on the left less than or equal to the value on the right
i.e. if a is less than or equal to b
>=
$a >= $b
==
$a == $b
Boolean equal;
are the left and right sides equal
i.e. if a is equal to b
!=
$a != $b
&&
$a && $b
Logical AND;
If the left and right sides are both true then the expression is true
If expression a is true and expression b is true
||
$a || $b
Logical OR;
If either the left or right side are true then the expression is true
i.e. If expression a is true or expression b is true
The last two operators can be combined to form complex boolean expressions using the and (&&) and or
(||) operators that perform comparisons on many arguments. The truth table below explains the results of
using and (&&) and or (||) in Boolean expressions.
&& (and)
|| (or)
True
False
True
False
True
true
false
true
true
False
false
false
true
false
Note:
The actual representation in Tcl for false is 0 and for true is anything but 0.
Page 64 of 81
The if Command
The if Command
The Tcl if statement is used to branch to a section of code to be executed based upon a Boolean
expression. There are four possible forms of the if command.
2. Now run Task09_1.tcl. Your results in the message window will vary according to your input
value.
Page 65 of 81
The if Command
2. Now run Task09_2.tcl and inspect the results. Your results in the message window will vary
according to your input value.
Page 66 of 81
The if Command
225} {
315} {
360 ||
45} {
2. Now run Task09_3.tcl and inspect the results. Your results in the message window will vary
according to your input value.
Page 67 of 81
The if Command
2. Now run Task09_4.tcl and inspect the results. Your results in the message window will vary
according to your input value.
Page 68 of 81
2. Now run Task09_5.tcl and inspect the results, they should appear as below
d1
d2
d3
d4
d5
Page 69 of 81
2. Now run Task09_6.tcl and inspect the results, they should appear as below
This is the 1 time through the loop
This is the 2 time through the loop
This is the 3 time through the loop
This is the 4 time through the loop
This is the 5 time through the loop
This is the 6 time through the loop
This is the 7 time through the loop
This is the 8 time through the loop
This is the 9 time through the loop
This is the 10 time through the loop
Note:
The incr command as used above will add 1 to the variable count. incr can take a second parameter such as incr
count 1 which will be added to the variable which is useful when it is required to loop backwards.
Page 70 of 81
Page 71 of 81
SclRangeExpand
SclRangeExpand
The SclRangeExpand command takes a Surpac range specification like 100, 200, 10 and then expands
it out into its individual components in memory. Once a range specification has been expanded in
memory you can access information on it using the other Scl range functions.
Syntax
SclRangeExpand RangeHandle RangeExpression
Where
RangeHandle is a reference variable that you will use to access the expanded range i.e.
secRange, inputRange, filelds, etc
RangeExpression is the actual range that is being expanded i.e. 1000, 2000, 100
Return Values
SCL_OK if the function creates the form object with no error
SCL_ERROR if something goes wrong
As an example the range specification 1000, 2000, 100 would expand into the following series of values
in memory:
1000
1100
1200
1300
1400
1500
1600
Page 72 of 81
1700
1800
1900
2000
SclRangeGetCount
SclRangeGetCount
The SclRangeGetCount command will get a count of the number of items in a range that has been
previously expanded in memory using the SclRangeExpand function.
Syntax
SclRangeGetCount RangeHandle
Where
RangeHandle is the reference handle (variable) that was created after perfoming
SclRangeExpand i.e. $secRange, $inputRange, $fileIds, etc
Return Values
SCL_OK if the function creates the form object with no error
SCL_ERROR if something goes wrong
Using the previous example the returned range count would be 11 for the range 1000, 2000, 100
SclRangeGet
The SclRangeGet command will get a range value at the specified position in a range that has been
previously expanded in memory using the SclRangeExpand function.
Syntax
SclRangeGet RangeHandle RangePosition RangeValue
Where
RangeHandle is the reference handle (variable) that was created after perfoming SclRangeExpand
i.e. $secRange, $inputRange, $fileIds, etc
RangePosition is the position in the range to get the value for. Note that the first item in the range
is at position 0
RangeValue is the name of a variable to store the range value into i.e. secNum, Id, bench, etc. If
the variable doesnt exist it will be created.
Return Values
SCL_OK if the function creates the form object with no error
SCL_ERROR if something goes wrong
Note:
The range position starts at zero and not one! See the following example for the range 1000, 2000, 100
th
st
nd
rd
th
th
th
th
th
th
th
10
1000
1100
1200
1300
1400
1500
1600
1700
1800
1900
2000
Page 73 of 81
Page 74 of 81
3. Add a form to the top of the script to get any value for the sec_range variable. Use the code as
supplied below.
set form_def {
GuidoForm form {
-label "Surpac Ranges"
-default_buttons
GuidoField sec_range {
-label "Enter a range"
-format range
-width 20
-null false
}
}
}
SclCreateGuidoForm form_handle $form_def {}
$form_handle SclRun {}
4. Try a number of different range entries including non-uniform range values like
a.
b.
c.
d.
100,200,25;235;256;300,500,50
100
1,10
1000,1020,5;1002;1020,5
Page 75 of 81
Examples
set read_file [open datafile.dat r]
set write_file [open newfile.dat w]
Note:
Note that the open command returns a reference value that you store into a variable. You use this variable to
later refer to the opened file with other Tcl commands that you use to access the file.
Examples
close $read_file
close $write_file
Page 76 of 81
Examples
Note:
With the examples above the actual data will be placed into memory variables called line and inputData.
Page 77 of 81
Writing to a file
Example
Writing to a file
There are a couple of Tcl commands that allow you to write to files called puts and write. The write
command is more advanced and allows block i/o. You have already used the puts command for writing
to the message window but it can also be used to write a line to a file opened for writing.
Examples
puts $write_file some text to write to the file
puts $write_file $processedData
Page 78 of 81
A File-Processing Template
A File-Processing Template
The commands discussed previously are all you require for simple file processing applications. The
example below will give you a template that will work in most instances that you will tackle. It simply
opens one file for reading, one for writing, reads each line from the read file and writes the lines to the
new file, and finally closes both files.
2. Now run Task11_1.tcl and inspect the results in the file new1.str. The template simply copies
the contents from one file unaltered. In practice your script would normally process the data being
read in before outputting it.
Page 79 of 81
Tcl References
Tcl References
Online Reference Manual
Surpac includes a complete Tcl on-line reference manual that describes each of the Tcl commands in
detail. It also includes a complete Scl & GUIDO reference manual, with examples to demonstrate how
each of the Scl commands can be used.
Text books
Practical Programming in Tcl and Tk
Brent Welch. Prentice Hall, 1999. 3rd Ed
ISBN: 0-13-022028-0.
Page 80 of 81
Tcl References
WWW resources
WWW resources
There are a huge number of internet sites site dedicated to the Tcl language as well as a number that
offer Tcl solutions. The Scriptics site is the best place to begin looking and contains a link page to a
number of other resources.
http://www.tcl.tk
http://dev.scriptics.com/resource/community/websites/
The mine solutions initiative is dedicated to promoting third party Surpac developments. It also contains
resources and tips and tricks in using Tcl/Scl. vComp Pty Ltd manages the development and associated
web site.
www.minesolutions.com
info@minesolutions.com
Of course there is always the GEMCOM web site that provides links to a number of third party Tcl
Resources as well as a number of free scripts for download.
www.gemcomsoftware.com
Page 81 of 81