I try to learn from Oliver's corner instruction ftp://ftp.safe.com/fme/pyfme/OliversCorner.zip) . So for example I overwrite his #script 4 to StartupPython Script some below and set input data in workflow with name "Fruits":
class MyPythonFactory(object):
def __init__(self):
self.count_features = 0
self.logger = pyfme.FMELogfile()
def input(self,feature):
self.count_features += 1
# Accessing all attributes of a feature
self.all_attributes = 'Tile'.getAllAttributeNames() # return a list with all attribute names as result
self.all_attributes_count = len(self.all_attributes) # count attributes
self.logger.log('Feature: '+ str(self.count_features),1)
for i in range(self.all_attributes_count):
self.attribute_name = self.all_attributes[i] # get attribute name
self.attribute_value = 'Tile'.getAttribute(self.attribute_name) # get attribute value
self.logger.log('Attribute: ' + str(self.attribute_name) + '\tValue: ' + str(self.attribute_value), 1)
self.logger.log('\n',1)
self.pyoutput('Tile')
def close(self):
self.logger.log('Total number of features: ' + str(self.count_features),1)
And according to this I should get following results in log file:
Feature: 1
Attribute: X_INT Value: 3333317
Attribute: ID Value: 1
Attribute: fme_type Value: fme_point
Attribute: LASTNAME Value: von Goethe
Attribute: Y_INT Value: 5684892
Attribute: fme_feature_type Value: points
Attribute: fme_geometry Value: fme_point
Attribute: SHAPE_GEOMETRY Value: shape_point
Attribute: X_FLOAT Value: 3333317
Attribute: SURNAME Value: Johann Wolfgang
Attribute: Y_FLOAT Value: 5684892
But I do not get any results of this script in logfile!
So my questions are:
- How script recognize which feature I will use If there are more? Is feature name actually name of input data for example, so I should use 'Fruits'?
- Do I have to replace word 'feature' in code with corresponding feature name in workbench?
-
2Please provide a link to the original code that you are modifying.Chad Cooper– Chad Cooper2011年10月06日 13:02:16 +00:00Commented Oct 6, 2011 at 13:02
-
link is above. Thank you very much for suggestioN!Z77– Z772011年10月06日 13:38:38 +00:00Commented Oct 6, 2011 at 13:38
-
2Personally I have not been able to get a grasp of Python in FME either, except for scripted parameters. Thankfully they are rewriting the Python FME API (and actually documenting it this time) for FME 2012: fmepedia.safe.com/articles/FAQ/…blah238– blah2382011年10月06日 22:43:32 +00:00Commented Oct 6, 2011 at 22:43
1 Answer 1
That Python snippet is not appropriate for a Startup Python Script. It's purpose is to process features, so you need to place it in a PythonCaller transformer.
http://docs.safe.com/fme/html/FME_Transformers/content/transformers/pythoncaller.htm
Startup Python Scripts would not typically operate on features, but could be used to do more generic preparation before the workspace is run.