Skip to main content
Question

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


Forum|alt.badge.img

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

Forum|alt.badge.img
  • August 29, 2019

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.


jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • August 29, 2019

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.

lifalin2016
Contributor
Forum|alt.badge.img+29
  • Contributor
  • March 3, 2023
jdh wrote:

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.


jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • March 3, 2023
lifalin2016 wrote:

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.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings