Question

How to pass a user parameter to a custom transformer and used in a pythonCaller?

  • 29 August 2019
  • 4 replies
  • 67 views

Badge

How does one pass a user parameter to a pythonCaller that's inside a customTransformer

import fme
import fmeobjects
 
def processFeature(feature):
    p = FME_MacroValues['SomeUserParameter']
    print p 

I read here "If you put your pythonCaller inside a custom transformer, the parameter name changes to {customTransformerName}_SomeUserParameter. "

I tried then doing this below but still does not work.

import fme 
import fmeobjects  
def processFeature(feature):
     p = FME_MacroValues['{customTransformerName}_SomeUserParameter']     
     print p 

What am I doing wrong?

 


4 replies

Badge

Try to put a ParameterFetcher in the Main part of the workspace and fetch your user parameter. Then go into the custom transformer, open the settings for the Input and expose your parameter.

Badge +22

It's not the custom transformer name, it's the custom transformer instance name, so if you have two instances of the custom transformer, the MacroValues are going to be different.

 

 

It's much better to use a parameterFetcher inside the custom transformer to store your parameter as an attribute, and then reference it by feature.getAttribute('_ParamAttr'). This will be consistent no matter how many times the custom transformer is used, or renamed.
Userlevel 1
Badge +22

It's not the custom transformer name, it's the custom transformer instance name, so if you have two instances of the custom transformer, the MacroValues are going to be different.

 

 

It's much better to use a parameterFetcher inside the custom transformer to store your parameter as an attribute, and then reference it by feature.getAttribute('_ParamAttr'). This will be consistent no matter how many times the custom transformer is used, or renamed.

This is the sensible approach. The parameter naming inside custom transformers is horrible. Fortunately one can easily clean up all the internal attributes when outputting features from the transformer.

Badge +22

This is the sensible approach. The parameter naming inside custom transformers is horrible. Fortunately one can easily clean up all the internal attributes when outputting features from the transformer.

All my temporary attributes inside a custom transformer begin with ! so they are exceedingly unlikely to conflict with existing data, no matter who is using the custom transformer.

Even better is to use a specific prefix for each custom transformer. ex !GAC_ for GeographicalAreaCalculator.

Reply