Skip to main content
I wrote a script that calculates something with some attributes of a dataset and stores new attributes, something like

 

 

...

 

for AttributeName in MyFMEObject.AllAttributeNames()

 

  if AttributeNamet:6]!='LIST_' 

 

    MyFMEObject.setAttribute("MAX_"+ParamAttributeName,-1)

 

    MyFMEObject.setAttribute("MIN_"+ParamAttributeName,1000000)

 

 

for AttributeName in MyFMEObject.AllAttributeNames()

 

  if AttributeName :6]=='LIST_' 

 

    CalcMaxMin(AttributeNamel-8:])

 

    MyFMEObject.setAttribute("MAX_"+ParamAttributeName,-1)

 

    MyFMEObject.setAttribute("MIN_"+ParamAttributeName,1000000)

 

    MyFMEObject.removeAttribute(AttributeName)

 

 

def CalcMaxMin(ParamObject, ParamAttributeName):

 

  localValue=ParamObject.getAttribute(ParamAttributeName)

 

  localMaxValue=ParamObject.getAttribute("MAX_"+ParamAttributeName)

 

  localMinValue=ParamObject.getAttribute("MIN_"+ParamAttributeName)  

 

  if localValue<localMinValue:

 

    ParamObject.setAttribute("MIN_"+ParamAttributeName,localValue)

 

   if localValue>localMaxValue:

 

    ParamObject.setAttribute("MAX_"+ParamAttributeName,localValue) 

 

 

it is shortened and only a not tested example, in reality I split the listnames in parts (cause it is not a list in python- style, is it?) and do some more.

 

 

from Attribute MYVALUE1, MYVALUE2 ... I created

 

MAX_MYVALUE1, MIN_MYVALUE1, MAX_VALUE2 ...

 

 

how can I publish this for next transformer, if I do not know at design time, what Attributes I get?
Hi,

 

 

You can only expose attributes known at design-time, as far as I know. So no luck, I'm afraid.

 

 

Your best bet is probably to set your attribute names to a list or a group of attributes with fixed names.

 

 

You might already know this, but you can create lists dynamically in a PythonCaller with something like:

 

 

for n, value in enumerate(mylist):

 

    feature.setAttribute("MyList{"+str(n)+"}.Value", value)

 

 

where you expose "MyList{}.Value" in the PythonCaller config. You can then use the ordinary list transformers in FME to access all the values in the list.

 

 

David
I did not try this. It seems to me that there is a methode "Publish" missing.

 

In my case I needed this once (for abot 20 attributes, was a copy/paste - orgy) and I can not make a "useful" custom transformer.

 

By using the Lists it probably would be possible to build such one, but the usebility of the list elements is not that easy, as I would like. If I understand it correct the transformer would do like this:

 

 

For all Fields A,B,C ... should be created MaxA, MinA, AvgA, ... AvgC ...

 

I could say ListMin, ListMax, ListAvg are published and I would create

 

ListMini0].A, ListMini0].B ...

 

and had manually to create in a following transformer 

 

MinA=ListMinA0].A, MinB=ListMinB0].B ... AvgC=ListAVGC0].B

 

 

So I have - depending on the number of fields - a lot of manual work.

 

 

But thank you for your answer, I try this next time. 

 

 

Andreas

 

 


Hi knowing ones,

 

 

Is there a way now?

 

 

Another matter same question.

 

There is a database and something like

 

 

SELECT TABLE_NAME,ID FROM MY_SPECIAL_VIEW;

 

 

TABLE1, 12345;

 

TABLE1, 23456;

 

TABLE2, 34567;

 

 

and in the python caller I need to read the information as

 

 

SELECT * FROM TABLE1 WHERE ID = 12345;

 

 

ID = 12345;

 

NAME = "Hello";

 

ADDRESS = "World";

 

WSXDR = "YSEDC"

 

 

And I need to expose the Attributes ID, NAME, ADDRESS and WSXDR and maybe a control structure as MyDict {TABLE1:(ID,NAME,ADDRESS,WSXDR)}

 

 

Later I need to create a layer for each table in which are only the rows of this table with the correct content.

 

 

If I can't do this automatically I must build a special way for each table what is much work at once and I need to take care for every changing of the DB- Structure.

 

 

So I hope there is a dynamic/generic way that I can go.

 

 

Thanks in advance

 

Andreas

 

 

Reply