Synchronize Multiple User Parameter Values

(FME 2014 build 14235)

The green shape is a 3D polygon. Consider calculating its perimeter and area in 2D or 3D.

The calculation itself is easy. Just use a LengthCalculator and an AreaCalculator.

Parameter Settings
TransformerParameter NameChoice for 2DChoice for 3D
LengthCalculatorLength Dimension23
AreaCaluculatorTypePlane AreaSloped Area

Now, assume that there is a requirement that either 2D or 3D has to be determined through a user parameter at run-time.
It's easy to create two published parameters linked to the two transformer parameters separately, but the user will have to always be careful of their consistency. Ideally, it's better that the two parameter values can be specified simultaneously through setting just one published parameter. In other words, the two parameter values should be synchronized.

If value choices of the two transformer parameters were same, you could link both of them to the same user parameter. However, as shown in the table, those are different in fact.
In such a case, I would create a published parameter and a private scripted parameter so that value of the private parameter would be determined depending on value of the published parameter.
For example:

Published Parameter
Type: Choice
Name: DIM
Configuration: 2%3

Private Parameter
Type: Scripted (Python) or Scripted (Tcl)
# Parameter Value (Python Script) Example
return 'Plane Area' if FME_MacroValues['DIM'] == '2' else 'Sloped Area'
# Parameter Value (Tcl Script) Example
if {$FME_MacroValues(DIM) == 2} {set t "Plane Area"} else {set t "Sloped Area"}
return $t

This Tcl script is also available.
array set a {2 "Plane Area" 3 "Sloped Area"}
return $a($FME_MacroValues(DIM))

And then, specify $(DIM) to "Length Dimension" of the LengthCalculator, $(AREA_TYPE) to "Type" of the AreaCaluclator. User doesn't need to be careful of the consistency of the two parameter values no longer.

Other than the LengthCalculator and AreaCalculator, there are several transformers which have a parameter choosing 2D or 3D. Parameter names and value choices are various.
TransformerParameter NameChoice for 2DChoice for 3D
MeasureGeneratorLength Dimension23
SnipperMeasurement Mode2D3D
(Duplicate Consecutive Points)
Check Z ValuesNoYes

At first, I expected that I could do that with "Choice with Alias" parameter, rather than script.
Type: Choice with Alias
Configuration: 2,Plane<space>Area%3,Sloped<space>Area
Default Value: $(DIM)
But unfortunately value of this parameter became the same value as $(DIM), i.e. 2 or 3.
Why not?

No comments:

Post a Comment