Type: Scripted (Python) and Scripted (Tcl)
FMEpedia > Python and FME Basics > Scripted Parameters
Community > Create a Reader based on User Choice
In fact, I've never used scripted parameters in any practical projects...
-----
2013-10-30
Maybe this is a practical example.
> Specify Log File Name
-----
Welcome! This blog is my personal memorandum about FME. Feel free to leave your comments. ようこそ!このブログはFMEに関する私の個人的な覚書です。コメントを歓迎します。欢迎您!这博客是我对FME个人备忘录。感谢您的任何意见。
2013-05-28
2013-05-22
Referring to other User Parameter value in a User Parameter setting
$(PARAM_NAME)
this syntax in a parameter setting represents another parameter value in the same worksapce.
Community > Prompt for 'reader'/ 'writer'
this syntax in a parameter setting represents another parameter value in the same worksapce.
Community > Prompt for 'reader'/ 'writer'
2013-05-21
Date / Datetime string in FME
FME converts a datetime value read from a source dataset into 'YYYYmmddHHMMSS.000' string - having a decimal fraction.
Since the DateFormatter transformer doesn't recognize a digit string with a decimal fraction as a datetime representation, we have to round it before formatting with the transformer.
And we also have to format a date / datetime string into 'YYYYmmdd' or 'YYYYmmddHHMMSS' before writing it into a date / datetime type attribute (field) of a destination dataset.
Community > MS SQL Server Writer: Failed to parse `Date' from attribute value
=====
2013-11-01
There seems to be a case that the Excel writer doesn't convert a datetime string to a datetime value. Quote my post for the Community:
"I tested Excel writer in FME 2013 SP4, Windows Xp SP3.
Input datetime string format is YYYYmmddHHMMSS in all cases.
Results:
1) XLS_ADO writer, Excel version 97/2000/2002/2003 (*.xls)
Writer User Attribute Type = datetime
The value is written as a datetime value. But the field format cannot be specified in FME, it has to be modified manually after writing if necessary.
2) XLS_ADO writer, Excel version 2007 (*.xlsx)
Writer User Attribute Type = datetime
The value is written as a character string. Why?
3) XLSXW writer (new Excel writer added in FME 2013 SP2)
Writer User Attribute Type = datetime
The value is written as a datetime value, and also the field format (e.g. yyyy-mm-dd) can be specified in the writer feature type dialog box."
-- Community > Change ouput format of datetime in Excel_ADO Writer?
Since the DateFormatter transformer doesn't recognize a digit string with a decimal fraction as a datetime representation, we have to round it before formatting with the transformer.
And we also have to format a date / datetime string into 'YYYYmmdd' or 'YYYYmmddHHMMSS' before writing it into a date / datetime type attribute (field) of a destination dataset.
Community > MS SQL Server Writer: Failed to parse `Date' from attribute value
=====
2013-11-01
There seems to be a case that the Excel writer doesn't convert a datetime string to a datetime value. Quote my post for the Community:
"I tested Excel writer in FME 2013 SP4, Windows Xp SP3.
Input datetime string format is YYYYmmddHHMMSS in all cases.
Results:
1) XLS_ADO writer, Excel version 97/2000/2002/2003 (*.xls)
Writer User Attribute Type = datetime
The value is written as a datetime value. But the field format cannot be specified in FME, it has to be modified manually after writing if necessary.
2) XLS_ADO writer, Excel version 2007 (*.xlsx)
Writer User Attribute Type = datetime
The value is written as a character string. Why?
3) XLSXW writer (new Excel writer added in FME 2013 SP2)
Writer User Attribute Type = datetime
The value is written as a datetime value, and also the field format (e.g. yyyy-mm-dd) can be specified in the writer feature type dialog box."
-- Community > Change ouput format of datetime in Excel_ADO Writer?
=====
2013-05-19
FME stores all attributes as character strings
FME Workbench > FME Architecture (Reference) > Attributes
"Feature attributes are usually a primitive type: integers, floats, characters. Internally, FME stores all attributes as character strings and automatically converts between a string representation and a numeric representation as needed."
"Feature attributes are usually a primitive type: integers, floats, characters. Internally, FME stores all attributes as character strings and automatically converts between a string representation and a numeric representation as needed."
=====
2015-05-07: Unfortunately the page has been retired. The URL is invalid now.
=====
But, we can change the type through Python script if necessary and convertible.
Community > How to coerce attribute type for JSONTemplater?
-----
2013-09-30
Continue to FME stores all attributes as character strings: Part 2
-----
2015-05-07: Unfortunately the page has been retired. The URL is invalid now.
=====
But, we can change the type through Python script if necessary and convertible.
Community > How to coerce attribute type for JSONTemplater?
-----
2013-09-30
Continue to FME stores all attributes as character strings: Part 2
-----
2013-05-18
Parsing attribute values
Community > Parsing attribute values
- StringSearcher or AttributeSplitter
- Tester
- StringReplacer or StringConcatenator
I would use a combination of StringSearcher and StringReplacer with:
^(.+) to (.+)$
# Python script also can be used.
import fmeobjects
import re
class UpDownRegulator(object):
def __init__(self):
self.attrName = 'up_to_down'
self.regex = re.compile('^\s*(.+)\s+to\s+(.+)\s*$')
def input(self, feature):
s = feature.getAttribute(self.attrName)
if s:
m = self.regex.match(s)
if m:
u, d = m.group(1), m.group(2)
if u < d: u, d = d, u
feature.setAttribute(self.attrName, '%s to %s' % (u, d))
self.pyoutput(feature)
def close(self):
pass
- StringSearcher or AttributeSplitter
- Tester
- StringReplacer or StringConcatenator
I would use a combination of StringSearcher and StringReplacer with:
^(.+) to (.+)$
# Python script also can be used.
import fmeobjects
import re
class UpDownRegulator(object):
def __init__(self):
self.attrName = 'up_to_down'
self.regex = re.compile('^\s*(.+)\s+to\s+(.+)\s*$')
def input(self, feature):
s = feature.getAttribute(self.attrName)
if s:
m = self.regex.match(s)
if m:
u, d = m.group(1), m.group(2)
if u < d: u, d = d, u
feature.setAttribute(self.attrName, '%s to %s' % (u, d))
self.pyoutput(feature)
def close(self):
pass
Sort only part of an attribute in a list
Community > Sort only part of an attribute in a list
# Python script version
# Python script version
import fmeobjects
import re
AttrName = ['field0', 'field1', 'field2', 'field3']
def sortAttributes(feature):
v = {}
for n in AttrName:
s = feature.getAttribute(n)
if s and re.match('^.+_.+$', s): v[s.split('_')[-1]] = s
i = 0
for k in sorted(v.keys()):
feature.setAttribute(AttrName[i], v[k])
i = i + 1
for j in range(i, len(AttrName)):
feature.setAttribute(AttrName[j], '')