FME Function and TclCaller

(FME 2014 build 14235)

I discovered by chance that this documentation has been enabled.
> FME Factory and Function Documentation

In a workspace, any FME Function can be called with the FMEFunctionCaller transformer. If the function returns a value, it can be also used in an expression for value setting of many transformers such as AttributeCreator, ExpressionEvaluator etc.. And also, as I mentioned before, they can be called directly from a Tcl script embedded in a TclCaller.
2014-03-25: Of course any FME Function can be also called using the PythonCaller.
See the next article > FME Function and PythonCaller

I tested some functions with TclCaller. Use FME_Execute proc. to call a function in the script.
The syntax is:
FME_Execute <function name without @> [<arg1> <arg2> ... ]

Example 1: Merge Multiple List Attributes
Using @MergeLists function, two or more list attributes can be merged at once.
@RemoveAttributes function removes all the specified attribute(s) including list.
Assume input feature has two list attributes named "_list1{}", "_list2{}". This script creates a new list attribute named "_merged{}" by merging them and removes the original lists.
proc mergeLists {} {
    FME_Execute MergeLists "_merged{}" "_list1{}" "_list2{}"
    FME_Execute RemoveAttributes "_list1{}" "_list2{}"
If you don't need to remove the original lists, the FMEFunctionCaller can be used with this parameter setting.
FME Function: @MergeLists(_merged{},_list1{},_list2{})
# Why isn't there "ListMerger" transformer?

Example 2: Remove Duplicate Vertices from Polygon
@GeometryType function is interesting.
If no argument was given, it returns a geometry type identifier of the feature. e.g. fme_point, fme_line, fme_polygon etc..
If fme_polygon was given as its argument, it removes duplicate vertices from the polygon.
Other than above, this function has also several options.
This script identifies geometry type of input feature and removes duplicate vertices when the type is fme_polygon.
proc removeDuplicateVertices {} {
    if {[string compare [FME_Execute GeometryType] fme_polygon] == 0} {
        FME_Execute GeometryType fme_polygon
If geometry type of input feature is always fme_polygon, the FMEFunctionCaller can be used with this parameter setting.
FME Function: @GeometryType(fme_polygon)

Example 3: Set Z Values to Coordinates
@NumCoords returns number of coordinates of the feature.
@NumElements <list name> returns number of the list elements.
@Dimension 2|3 forces the feature to 2D|3D.
@ZValue <list name> set Z values stored in the list to coordinates of the feature.
Assume input feature has a list attribute named "_z{}" storing numeric values. This script set Z values stored in the list to coordinates of the feature when number of the list elements is equal to number of the coordinates.
proc setZValues {} {
    set n [FME_Execute NumCoords]
    if {0 < $n && $n == [FME_Execute NumElements "_z{}"]} {
        FME_Execute Dimension 2
        FME_Execute ZValue "_z{}"
        return "success"
    } else {
        return "failure"
In my testing, @ZValue function did nothing if coordinates had Z values already. So I've used @Dimension function to force the feature to 2D beforehand.


No comments:

Post a Comment