I'm trying to write a custom transformer with a python script that looks at the Public Parameter.
There is a lot of trial and error going on but I think I'm doing it as it should now.
This helped me getting started:
https://knowledge.safe.com/questions/44873/getting-published-parameters-from-within-a-python.html
The transformer works if the Public Parameter is set to a fixed value or if it is set to a feature attribute value. But when there are two instances of the Custom Transformer it looks at whatever starts first. So the second transformer uses the fixed value of the first transformer.
custom_transformer_name = 'MultiInstanceBug'
parameter_name = 'codeLength'
instance_name = FME_MacroValues[custom_transformer_name + '_WORKSPACE_NAME']
mv_codeLength = FME_MacroValues[instance_name + '_' + parameter_name]
if mv_codeLength[0:6] == '@Value':
codeLength = int(feature.performFunction(mv_codeLength))
elif mv_codeLength[0:6] == '@Evalu':
codeLength = int(feature.performFunction(mv_codeLength))
elif mv_codeLength != '':
codeLength = int(mv_codeLength)
else:
codeLength = 0
logger.logMessageString('codeLength: ' + str(codeLength),fmeobjects.FME_INFORM)
This gives unexpected results, the only workaround I now see is using an AttributeCreator and AttributeRemover to write the value to the feature first.
See the workbench I created:
Best answer by geosander
View original