0

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:

  1. 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'?
  2. Do I have to replace word 'feature' in code with corresponding feature name in workbench?
chrki
2,68517 silver badges23 bronze badges
asked Oct 6, 2011 at 11:46
3
  • 2
    Please provide a link to the original code that you are modifying. Commented Oct 6, 2011 at 13:02
  • link is above. Thank you very much for suggestioN! Commented Oct 6, 2011 at 13:38
  • 2
    Personally 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/… Commented Oct 6, 2011 at 22:43

1 Answer 1

2

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.

answered Oct 7, 2011 at 2:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.