Question

What is the TCLCaller?

Answer

TCLCaller

TCLCaller is a Workbench Transformer. The TCLCaller evaluates an arbitrary Tool Command Language (Tcl) 8.4.9 expression and assigns its return value to an attribute.

The Tcl command can operate on the feature’s geometry and/or attributes, using any of the built-in Tcl functions provided by the Tcl language, as well as any of the FME provided Tcl facilities. See the Tcl language reference manual (http://www.tcl.tk/) and the FME Tcl function in the FME Functions and Factories Manual for details of the capabilities.

Common Tcl  usage includes:

Trim spaces from an attribute:

    FME_SetAttribute trimmedAttribute [string trim [FME_GetAttribute originalAttribute]]


Replace all non-numeric characters with spaces in an attribute:

    FME_SetAttribute anAttribute [regsub -all {[^0-9]} [FME_GetAttribute anAttribute)] {}]

Note that in this case, the return value is the number of substitutions actually made.


Match a regular expression against an attribute:

    regexp {^[A-Za-z]$} [FME_GetAttribute anAttribute] 

This regular expression tests if the entire value of the attribute consists only of alphabetic characters. Note that when matching regular expressions, the return value will be 1 if the expression matched, and 0 otherwise.


Log a custom message to the log window:

    FME_LogMessage fme_inform This is my message


The recommended way to manipulate feature attributes is through the functions that are provided for this purpose:

    FME_GetAttribute attrName
    FME_SetAttribute attrName newVal
    FME_CopyAttribute destAttrName srcAttrName
    FME_RenameAttribute destAttrName srcAttrName
    FME_UnsetAttributes attrName1 [attrName2 attrName3 ...]


If "Yes" is chosen for the "Use FME_Attributes array" parameter, then access will be provided to an array named FME_Attributes, and each attribute can be fetched or set with the name FME_Attributes(attrName). Note that this slows down execution time significantly.


A Tcl source file can optionally be provided. The file will be read before the Tcl command is executed. This can be used to reference Tcl functions kept in a common external file.


Note: Note that due to FME parser limitations, a Tcl expression cannot contain a % character. If a % character is needed, then the expression should be coded as a Tcl procedure and put into an external file to be 'source'd in. Further note that the StringFormatter transformer provides a convenient way to access the Tcl 'format' command thereby sidestepping the % character issue for this situation.