Solved

Can I pass multiple features to a Python Caller and use ArcPy in the script?

  • 11 August 2017
  • 5 replies
  • 12 views

Hi all,

I've got a question about integrating ArcPy in FME. It would appear that FME won't let me to read in multiple features and process them using ArcPy functions through PythonCaller. This can be easily done outside FME with one line of code such as:

arcpy.LocateFeaturesAlongRoutes_lr(feats, rts, rid, tol, tbl, props)

What I would hope to achieve with PythonCaller is that it can be used just like one of the transformers like clipper and buffer. Not sure anybody else has experienced the same issue?

Thanks!

icon

Best answer by courtney_m 11 August 2017, 19:54

View original

5 replies

Badge

@jonathanchiang0, yes, this is possible - you need to make sure you import arcpy in your script. Also, make sure you set the python interpreter in the navigation panel, as shown below:

As an example - In the screenshot below, I used a PythonCaller to take each incoming shapefile, check to see if it already exists in the specified geodatabase, and if the FC does not already exist, it imports the shapefile into the GDB.

Make sure you drag/drop parameters and attributes from the panel on the left.

-Courtney

Badge +16

Another option is a shutdown script.

Badge

Another option is a shutdown script.

If you decide to use a Shutdown Script, you will manually have to type in parameters with the following format: $(PARAM_NAME)

 

Another thing to be aware of with shutdown scripts, is that you cannot incorporate attribute values into your script.

 

 

An example of when it is a good idea to use a shutdown script, is if you want to compress a versioned GDB after your workspace is done writing to it. You would use the following shutdown script (where there is a user parameter called GEODATABASE_SDE_CONNECTION_FILE that references the appropriate file):

 

import arcpyarcpy.Compress_management('$(GEODATABASE_SDE_CONNECTION_FILE)')

@jonathanchiang0, yes, this is possible - you need to make sure you import arcpy in your script. Also, make sure you set the python interpreter in the navigation panel, as shown below:

As an example - In the screenshot below, I used a PythonCaller to take each incoming shapefile, check to see if it already exists in the specified geodatabase, and if the FC does not already exist, it imports the shapefile into the GDB.

Make sure you drag/drop parameters and attributes from the panel on the left.

-Courtney

@courtney_m Hi Courtney, Thanks a lot for providing such information. I am also wondering if it's possible to pass 2 or more feature types (data sets) to one python caller and let it process the data? In the python example I listed above, "feats" and "rts" represent 2 different feature classes and they were being gracefully processed through an arcpy function. Can FME handle such task?

 

 

Maybe I used the term "features" wrong, what I really meant is Feature Types or data sets. In the python example I listed above, "feats" and "rts" represent 2 different feature classes and they are gracefully being processed through an arcpy function. I am not sure if FME's Python Caller can handle multiple feature types at a time? Thanks.

 

 

Reply