Skip to main content
Question

New to FME - using PythonCaller - do I need to call the function that I created?

  • February 15, 2019
  • 3 replies
  • 314 views

I am using PythonCaller and have wrote a script for it. I have tested my script outside of FME and it works.

Script creates a column and calculates value for it.  When I run my fme, I am getting this error:

 

PythonFactory failed to load python symbol `processFeature(feature)'

Factory proxy not initialized

f_24(PythonFactory): PythonFactory failed to process feature

 

The PythonCaller Parameters:

0684Q00000ArEQ1QAN.png

 

Script:

import fme, fmeobjects
import arcpy

from collections import Counter

def processFeature(feature):
    # The location of the destination geodatabase and feature class
    feat_class = feature 
    # Add new field for new value
    arcpy.AddField_management(feat_class, "countVehicle""SHORT")

    # add all values for brigade unique id to a list
    all_values = list()
    with arcpy.da.SearchCursor(feat_class, ["T_LOCATION_CODE"]) as cursor:
        for row in cursor:
            all_values.append(row[0])
    
    # Calculate field
    fields = ["T_LOCATION_CODE""countVehicle"]
    with arcpy.da.UpdateCursor(feat_class, fields) as cursor2:
        for row2 in cursor2:
            if row2[0in Counter(all_values):
                row2[1] = Counter(all_values)[row2[0]]
                cursor2.updateRow(row2)

3 replies

ebygomm
Influencer
Forum|alt.badge.img+33
  • Influencer
  • February 15, 2019

In the class or function to process feature box you just want processFeature not processFeature(feature)


david_r
Celebrity
  • February 15, 2019
ebygomm wrote:

In the class or function to process feature box you just want processFeature not processFeature(feature)

Agree, specify only the function name, no arguments.


david_r
Celebrity
  • February 15, 2019

Also be aware that this probably won't work as you expect:

feat_class = feature 

"feature" will refer to an instance of fmeobjects.FMEFeature, not a string, and arcpy won't know what to do about it.

If the input feature contains the feature class name as an attribute, you can do something like:

feat_class = feature.getAttribute('my_attribute_containing_feature_class_name')

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