Skip to main content
Solved

How to treat all appearing lists at once within a dynamic workspace?

  • Apr 1, 2025 12:20 PM UTC
  • 3 replies
  • 142 views

frantsch
Contributor
Forum|alt.badge.img+5

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) ?

Best answer by takashi

​@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)[1:] if m.group(2) else m.group(1)
value = feature.getAttribute(attr)
feature.setAttribute(name, value)
self.pyoutput(feature)

 

View original
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.

3 replies

takashi
Celebrity
  • Apr 2, 2025 3:11 AM UTC

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")

 


frantsch
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • Apr 2, 2025 5:08 AM UTC

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)


takashi
Celebrity
  • Best Answer
  • Apr 2, 2025 11:05 AM UTC

​@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)[1:] if m.group(2) else m.group(1)
value = feature.getAttribute(attr)
feature.setAttribute(name, value)
self.pyoutput(feature)