6

I am trying to create an attribute index in a feature class in FME 2011. I couldn't find any transformer that does it. I'm thinking that maybe I can use "PythonCaller" transformer to call "Add Attribute Index" geoprocessing method from ArcMap.

Is it possible?

Here's the syntax I copied from ArcMap Help menu:

arcpy.AddIndex_management ("counties.shp", "NAME;STATE_FIPS;CNTY_FIPS", "#", "NON_UNIQUE", "NON_ASCENDING")

I intalled FME2012 on my machine and used python26.dll as my custon Python interpreter and copied @Mark's code. For Entry point, I entered the name of the class "MyIndexingScript". I'm getting the following error:

Python Exception : Object: Error in executing tool Error encountered while calling method `input' PythonFactory failed to process feature

import fmeobjects
import arcpy

class MyIndexingScript(object):
   def __init__(self):  
       self.featureList = []
   def input(self,feature):
       self.featureList.append(feature)
       arcpy.AddIndex_management (self, "YORK_PARCEL_ID;PARCEL_GIS_ID", "PIndex", "UNIQUE", "ASCENDING")
   def close(self):        
       self.pyoutput(feature)
4
  • Are you getting a error? If so, please paste in the whole error. Also, post all of the code from the PythonCaller. Commented May 9, 2012 at 19:34
  • Chad, I have no idea on how to call the process. The example I gave is the one I would like to call.
    – Sam
    Commented May 9, 2012 at 19:36
  • 1
    I don't think you can use self directly, as you are, in the arcpy.AddIndex_management call. Instead you will want to either hard-code the feature class path or read in an attribute or parameter to use there. So something like fc = self.getAttribute('FC_PATH') and then reference fc instead of self in the AddIndex call. See the PythonCaller help for more details.
    – blah238
    Commented May 11, 2012 at 5:34
  • According to SAFE support, the arcpy AddIndex function expects to be passed the path to an existing table, so the script needs to be run after the geodatabase has been created. The workaround is to copy the script into the Shutdown Python Script parameter (in the Navigator window, under Workspace Parameters > Advanced).
    – Sam
    Commented May 15, 2012 at 20:28

2 Answers 2

9

If you can use the File Geodatabase API writer in FME2012-SP2, then there will be a setting in the feature type/writer to enable setting an attribute index.

Unfortunately, for the moment, it's limited to only that writer (not the ArcObjects Geodatabase writer) which has a number of other limitations.

In the meantime you are correct, a call using the PythonCaller should work.

I am no Python expert, but you will need to make sure you call it as a Class and not a Function - because a function will execute once per feature, and you only need it to run once in total.

So I would think something like:

import arcpy
import fmeobjects

class MyIndexingScript(object):
def __init__(self):  
def input(self,feature):
def close(self):

arcpy.AddIndex_management ("counties.shp", "NAME;STATE_FIPS;CNTY_FIPS", "#", "NON_UNIQUE", "NON_ASCENDING")

...but you will want to check the help doc for the PythonCaller and probably take a look on fmepedia.com for examples. Also check out fmeevangelist.com and search for Python content. There are some examples I created that might be of use.

8

To use arcpy you will need to change the Python interpreter used by FME as arcpy requires its own Python interpreter (version 2.6.5 for ArcGIS 10.0).

For FME 2011 what you need to do is create and set the FME_PYTHON_VERSION environment variable to 2.6 (for ArcGIS 10.0, I believe it's 2.7 for ArcGIS 10.1) as described here:

For FME 2012 there is a Workbench option to set the Python interpreter DLL.

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.