Skip to main content

I have a FME 2022.1 Desktop workspace with dynamic reader and dynamic writer. The reader generates several lists in some feature classes, in addition to attributes.

How can I parameterize e.g. ListIndexer or ListExploder transformers to treat all appearing lists within various features of various feature classes streaming through my dynamic workspace at once, not explicitly knowing their list names (and hence not being able to indicate them as transformer parameter) ?

Hi ​@frantsch ,

I don't think you can use ListExplader or ListIndexer in your workspace unless you know the list name(s) when creating the workspace.

Instead, I think Python script (PythonCaller) might be available in some cases. For example, this script works like ListIndexer (List Index to Copy: 0) for all the lists in any input feature.

# PythonCaller, FME 2024.2+
import fme
from fme import BaseTransformer
import fmeobjects
import re

class FirstElementExtractor(BaseTransformer):
def __init__(self):
pass

def input(self, feature: fmeobjects.FMEFeature):
for attr in feature.getAllAttributeNames():
m = re.match(r'^(.+)\{0\}(\..+)?', attr)
if m:
name = m.group(2)(1:] if m.group(2) else m.group(1)
value = feature.getAttribute(attr)
feature.setAttribute(name, value)
self.pyoutput(feature, output_tag="PYOUTPUT")

 


Many thanks for your effort ​@takashi !

Sorry, I am not quite familiar with PythonCaller. Using your code in FME Desktop 2022.1 I obtain:

Python Exception <ImportError>: cannot import name 'BaseTransformer' from 'fme' (D:\Apps\FME_2022_1_3\python\fme.py)


@frantsch 

Since some codes in my previous script are available only in FME 2024 or later, it doesn’t work in FME 2022.

Try this script instead.  

import fme
import fmeobjects
import re

class FirstElementExtractor(object):
def __init__(self):
pass

def input(self, feature):
for attr in feature.getAllAttributeNames():
m = re.match(r'^(.+)\{0\}(\..+)?', attr)
if m:
name = m.group(2)r1:] if m.group(2) else m.group(1)
value = feature.getAttribute(attr)
feature.setAttribute(name, value)
self.pyoutput(feature)