SclMessage
Overview
The SclMessage command provides access to the software's messaging system to display information into the message windows. It can also be used to translate messages into the local language if the language is supported.
Synopsis
SclMessage <sub option><message key><optional parameters>
Description
The SclMessage command allows you to print information into the message window in a variety of formats by specifying a sub option. The available sub options are;
Print the message key text into the message window. If optional arguments are given they will be formatted into the message text as described below.
SclMessage print "Macro has complete successfully"
message
Same as print
SclMessage message "Another way to print a message"
debug
Print the message key text as a debug message. If debug messages are currently disabled via the Message Options settings then it will be filtered out and nothing will be visible in the message window
SclMessage debug "Reached point A in the macro, where is my bug"
warning
Print the message key text as a warning message. If warning messages are currently disabled via the Message Options settings then it will be filtered out and nothing will be visible in the message window
SclMessage warning "Macro cancelled"
error
Print the message key text as an error message. If the Beep for error messages option is set via the Message Options settings then the computers bell will also ring.
SclMessage error "Macro has complete successfully"
assist
The assist sub option will display the message text as an assist message in the status bar usually with a light yellow background. The assist message will remain until another assist message is displayed or until the noAssist sub option is called
SclMessage assist "Select the object to process"
noAssist
The noAssist option will clear any assist message that is currently displayed. The {} placeholder argument must be specified as the message key for noAssist.
SclMessage noAssist {}
translate
The translate option will format the message key and any of the optional arguments that may be specified and return the formatted text. This option does not display the message to the message window.
set formattedMsg [SclMessage translate "File {0} not found in {1}" "pit1.str" "PICKUPS:"]
Note that this example includes optional arguments and argument place holders. This mechanism is described in full below.
Argument Substitution
The message key argument that is passed to SclMessage can contain optional argument place holders that take the form {0}, {1}, {2}, ... These place holders will be replaced with optional arguments that you provide to SclMessage. the place holder {0} will be substituted with the first optional argument, {1} with the second argument, and so on.
An example that assumes 3 variables called strNo, segNo, and pntNo exist previously and contain the values 100, 5, and 65 respectively.
SclMessage print "Processing string {0}, segment {1}, point number {2}" $strNo $segNo $pntNo
Will produce the message
Processing string 100, segment 5, point number 65
Another Example that show the arguments holders can be mixed up through the message key
SclMessage print "String {0} : {2} points processing on segment {1} of string {0}" $strNo $segNo $pntNo
Will produce the message
String 100 : 65 points processing on segment 5 of string 100
An example that shows if you specify more place holders than arguments then the place holder remains unsubstituted in the message
SclMessage print "Processing string {0}, segment {1}, point number {2}" $strNo $segNo
Will produce the message
Processing string 100, segment 5, point number {2}
Arguments
- <sub option>
- <message key>
- <optional parameters>
A literal string to identify the sub function. Must be one of print|message|debug|warning|error|assist|noAssist|translate
The message text that may include optional argument places holders to be substituted for actual arguments specified in the optional parameters section
If you specify argument place holders in the message key then there should be an exact match of optional arguments here. For example if you insert the place holders {0} and {1} in the message key then two optional arguments are required.
Returns
True (Tcl value 1) in the case of all sub functions except translate. When you specify translate the formatted message is returned.
Examples
SclMessage print "A simple example to demonstrate using the SclMessage command in Surpac"
# Select a point and print its values:
# Note the use of SclMessage translate around the prompt message
# this ensures that the message would be translated into the local
# language if non English was being used
set status [SclSelectPoint point \
[SclMessage translate "Select the point of interest"] \
layer stringid segmentnum pointnum xp yp zp pointdesc]
if {$status == $SCL_ERROR} {
SclMessage error "No point was selected ... cancelling"
return
}
SclMessage print "Layer {0} : String {1} : Segment {2} : Point {3}" \
$layer $stringid $segmentnum $pointnum
SclMessage print "Macro completed"
|