Can I use a macro to replace a value in a Workbench transformer
From Fmepedia
Q) Can I use a macro to replace a value in a Workbench transformer?
A) In some cases, yes. But we're trying to stop this because putting macros into a field can interfere with legitimate uses of, for example, the $ character and cause the FME parser a lot of grief.
So you may find that this now is not permitted in places where it used to work. In preference you should use Published Parameters and the ParameterFetcher transformer.
If you insist on using Macros this is how:
Replacing a Value directly within a Transformer
The most common use of a user-defined MACRO is to replace what would normally be a fixed value within Workbench. A few examples are…
- In AttributeSetter instead of setting the ‘value’ field to a fixed value you could use a MACRO.
- When you insert a Constant, you can enter a MACRO instead of a fixed value.
- In a Tester instead of testing against a fixed value you can test against the value of a MACRO.
Macros are represented in Workbench using square brackets, for example $[macroname] whilst environmental variables are represented by curly brackets, for example ${FME_HOME}
For example in an AttributeSetter you could have...
myattribname $[attribvaluemacro]
Replacing a value outside a Transformer
Transformer settings make use of pre-defined FME macros so often you don’t need to create the MACRO, you just need to know the MACRO name to pass a value through to it.
To find a macro name you can…
1, Right-click the setting in the navigation pane (workspace tab) and choose 'always-prompt' or 'publish-parameter' as it is known from FME2005 onwards.
Then either...
2a, Right-click on the transformer in the workspace canvas and choose copy. Open a text editor such as Notepad, right-click and choose paste. A text definition of the transformer is pasted and reveals the name of the settings used.
...or...
2b, Save the workspace and open it in a text editor. Near the top of the file will be the command you would enter in a command window to run the workspace. Because you published the parameters you will see the macro for that parameter in the command (needs FME2005).
For example, to set the multiplier setting in an AreaCalculator, a copy and paste reveals…
DEFAULT_MACRO AREACALCULATOR_MULT 1
GUI FLOAT AREACALCULATOR_MULT AREACALCULATOR: Multiplier:
FACTORY_DEF * TeeFactory \
FACTORY_NAME AREACALCULATOR \
OUTPUT FEATURE_TYPE AREACALCULATOR_OUTPUT \
area @Area($(AREACALCULATOR_MULT))
…that the multiplier setting is a pre-defined FME MACRO called AREACALCULATOR_MULT which has a default value of 1.
So to call the workspace from the command line, and include a value for this setting, use the syntax:
fme <workspacename>.fmw --AREACALCULATOR_MULT 1
