Skip to main content
Question

python shutdown attribute from feature writer

  • June 28, 2016
  • 1 reply
  • 26 views

rudy_v
Contributor
Forum|alt.badge.img+6

I used a writer with the following code (working OK):

FeaturesWritten = str(FME_FeaturesWritten)

fcno = FME_FeaturesWritten.get(fc)

But i have changed it to a feature Writer (not working anymore): result is None

what should the code be to get the number of features written?

_total_features_written is the attribute in summary

1 reply

takashi
Evangelist
  • June 28, 2016

Hi @rudy_v, a possible way I can think of is to save the value of '_total_features_written' as a Python global variable using a PythonCaller following to the FeatureWriter. e.g.

# PythonCaller Script Example: Save the number of features written as a global variable.
def processFeature(feature):
    global features_written
    features_written = int(feature.getAttribute('_total_features_written')) 

The global variable can be referred directly in the shutdown script.

Note that the variable will not be defined when the translation is failed or the FeatureWriter writes no features. To prevent an unexpected error in such a case, it might be better to define and initialize the global variable with the startup script. e.g.

# Startup Python Script Example: Define and initialize the global variable.
features_written = 0

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings