Hi,
Â
Â
the user parameters behave a little bit differently inside a custom transformer. They are in fact prefixed with the name of the custom transformer to avoid collisions with the main workspace parameters. Example: if you have a custom transformer called "custtransf" with a published parameter called "custparam", you will have to refer to it like this.
Â
Â
value = FME_MacroValuesl"custtransf_custparam"]
Â
One other hand, I see that you populate a list of all the features in your input() method above. Unless you really need this, I would try to avoid it as it really fills up memory. I would consider doing something like this instead:
Â
Â
import fmeobjects class FeatureProcessor(object): Â Â def __init__(self): Â Â Â Â self.featureCount = 0 Â Â def input(self,feature): Â Â Â Â self.featureCount += 1 Â Â def close(self): Â Â Â Â message = FME_MacroValuesm'Message'] + str(self.featureCount) + '\\n' Â It should be both quicker and more efficient.
Â
Â
Hope this helps.
Â
Â
David
Thanks for your response David.
Â
Â
Do you know how I can access the right parameter from python. I tried using the FeatureCountLogger_WORKSPACE_NAME, but that doesn't seem te work. For each instance of the custom transformer I get the same result; the parameter of one of them.
Â
Â
import fmeobjects class FeatureProcessor(object): Â Â def __init__(self): Â Â Â Â self.featureCount = 0 Â Â def input(self,feature): Â Â Â Â self.featureCount += 1 Â Â def close(self): Â Â Â Â logger = open(FME_MacroValuesr'Summarylog'], "a") Â Â Â Â logMessage = FME_MacroValueslFME_MacroValues_'FeatureCountLogger_WORKSPACE_NAME'] + '_Message'] Â Â Â Â message = logMessage + str(self.featureCount) + '\\n' Â Â Â Â logger.write (message) Â Â Â Â logger.close()
Â
Hi,
Â
Â
this handy little snippet will print all the available key values in FME_MacroValues for you -- you are bound to find the key you search for there.
Â
Â
Insert it into a PythonCaller and it will add it all, nicely formatted, to your FME log window:
Â
Â
-----
Â
import fmeobjects import pprint  def showAllMacroValues(feature):   pp = pprint.PrettyPrinter(indent=4)   pp.pprint(FME_MacroValues)
Â
-----
Â
Â
David
Â
Â
Hi David,
Â
Â
I have three instances of my custom transformer:
Â
LoggerA, LoggerB & LoggerC.
Â
Â
When I print the FME_MacroValues I get all parameters three times for each transformer. So how do I know inside my custom transformer python code which parameter I must use, since to code is the same for each instance.
Â
Â
Inside LoggerA:
Â
 LoggerA_Message: "Total number of features"
Â
 LoggerB_Message: "Number of filtered features"
Â
 LoggerC_Message: "Number of unfiltered features"
Â
Â
Inside LoggerB:
Â
 LoggerA_Message: "Total number of features"
Â
 LoggerB_Message: "Number of filtered features"
Â
 LoggerC_Message: "Number of unfiltered features"
Â
Â
Inside LoggerC:
Â
 LoggerA_Message: "Total number of features"
Â
 LoggerB_Message: "Number of filtered features"
Â
 LoggerC_Message: "Number of unfiltered features"
Hi,
Â
Â
it will depend on what you're trying to accomplish.
Â
Â
If you need the total number of features in all of your workspace, I would use a Python shutdown script where you will already have a variable called "FME_TotalFeaturesWriten" (more info here) that you can print directly.Â
Â
Â
If you need a count per transformer, I would do only the counting in your custom transformer, setting a global Python variable with your counters. The counters could be based on a dictionary where your published parameter (name of counter, if you will) is used as the dictionary key. You could then output them in your workbench shutdown script.
Â
Â
David
Hi Koen,
I came across a similar problem with accessing custom transformer parameters from a PythonCaller node inside said custom transformer. I solved this with the following:
transformerName = "CUSTOM_TRANSFORMER_NAME"
Â
instanceName = fme.macroValuesstransformerName + '_WORKSPACE_NAME']
Â
keys =
for x in fme.macroValues.keys() if x.find(instanceName) >=0]
Â
params = {}
Â
for key in keys:
Â
paramsakey] = fme.macroValuesakey]
Â
cfg_CUSTOMPARAMNAME = paramspinstanceName + '_CUSTOMPARAMNAME']
Â
It needs to know the name you gave the custom transformer when you created it. It then uses this to query the workspace to find out what its instance name is. Then it looks for all parameters for that instance and puts it into a nice easy to find dict.
Hi @koen
I have had the same issue already a couple of times. For me the best workaround was to use a ParameterFetcher (or AttributeCreator / -Manager) and store the value of the parameter in an attribute. Doing so will allow you to use it easily in the PythonCaller. And everything will still work when you rename the CustomTransformer.
Good luck!
Hi @koen
I have had the same issue already a couple of times. For me the best workaround was to use a ParameterFetcher (or AttributeCreator / -Manager) and store the value of the parameter in an attribute. Doing so will allow you to use it easily in the PythonCaller. And everything will still work when you rename the CustomTransformer.
Good luck!
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.