Tcl
Quick Reference II


return to main index



Index


Measuring Elapsed Time


set t1 [clock clicks -milliseconds]
# lengthy operation goes here
set t2 [clock clicks -milliseconds]
  
puts "\nTime taken [expr $t2-$t1] ms"

Dividing the time by 1000 will convert milliseconds seconds.



Launching an Application


set ribpath "PATH_TO_A_RIB_FILE"
exec "prman" $ribpath

Set the full path to a RIB file to be rendered. Invoke prman using the exec command.



Simple regsub - Rib Example


set input "ShadingRate 5"
#set line "Some other text"
set rep "ShadingRate 10"
regsub {ShadingRate \d} $input $rep copy
puts $copy

This example assumes the user is copying a rib file line-by-line to another file (refer to file copying) and that the value of a RIB statement called ShadingRate must be changed to 10. Each line of text is processed by the regsub proc. If regsub finds a match the variable "copy" receives the rep'lacement text, otherwise the variable receives an unaltered copy of the input text. Uncomment the second line of text to confirm this example works as stated.



Simple regexp & regsub - Rib Example


set input {Surface "plastic" "float Ka" 1.0 "float Kd" 0.5}
  
if {[regexp {Surface "plastic"} $str]} {
    regsub {("float Kd") ([0-9]?.?[0-9]?)} $input {\1 0.98} copy
    puts $copy
    }


This example again assumes the user is copying a rib file line-by-line to another file (refer to file copying). The intention is to alter the value of a shader parameter called "Kd" belonging specifically to a shader called "plastic". However, "Kd" can also be specified by shaders other than "plastic". Initially the input is matched by regexp. Only if the line of text refers to "plastic" is regsub used to substitute the old value for the new value of "Kd"





© 2002- Malcolm Kesson. All rights reserved.