Skip to main content
Question

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

  • August 29, 2019
  • 4 replies
  • 354 views

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?

 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

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+40
  • 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
Supporter
Forum|alt.badge.img+40
  • Supporter
  • March 3, 2023

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+40
  • Contributor
  • March 3, 2023

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.