Question

ArcGIS workspaces in FME

  • 27 December 2016
  • 6 replies
  • 11 views

Userlevel 2
Badge +19

Good morning!

I want to execute a Python script that rebuilds the spatial index of a feature class. I have followed the steps described here: https://knowledge.safe.com/articles/1190/using-a-python-startupshutdown-script-to-perform-g.html

The script I use is the following:

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# test.py
# Created on:
#   (generated by ArcGIS/ModelBuilder)
# Description: 
# ---------------------------------------------------------------------------

# Set the necessary product code
import arceditor

# Import arcpy module
import arcpy

# Local variables:
TEST_sde = "C:\\Users\\TestUser\\AppData\\Roaming\\ESRI\\Desktop10.2\\ArcCatalog\\TEST.sde"

# Process: Rebuild Indexes
arcpy.RebuildIndexes_management(TEST_sde, "NO_SYSTEM", "TEST.DBO.FC_TEST", "ALL")

But everytime I run the the FME project I get this error:

Python Exception <ExecuteError>: Failed to execute. Parameters are not valid.

ERROR 000837: The workspace is not the correct workspace type.

If I run this in ArcMap with the same parameters, there is no error. So I don't understand why FME says the parameters are not valid.

Does anyone know something about this?

- FME Desktop 2016

- ArcGIS Desktop 10.2.2

- TEST.sde is a geodatabase in SQL Server 2008 R2

Thanks for any help provided!


6 replies

Badge +13

What is your Python Interpreter set to in Workbench? We use: C:\\Windows\\System32\\python27.dll

Also, you might want to use a UNC path vs. named path for your SDE connection file like this:

database_sde = (r"\\\\SERVERNAME\\FMEData\\DATABASE.sde")

Everything else looks okay.

 

Userlevel 4

A couple of things to try:

Insert a new line 16 containing

arcpy.env.workspace = TEST_sde

Move the "TEST.sde" connection file to a different directory that isn't associated with a particular user, e.g. c:\temp

Badge +11

Yes both great suggestions above.  Do try @david_r suggestion (setting the workspace) - you'll likely need quotes around the workspace name. 

I helped a customer not long ago where the error message returned was nothing related to the problem.   @mmccart refers the the python interpreter... which is a good check.  Are you using FME's default or Esri's?

I'll also mention another possible consideration.  We made a change in FME 2016.1 that does change what python libraries are loaded in some situations.   

Try reviewing the PATH using the PythonCaller to see what is there for python folders.  There is a chance that a different set of libraries is being loaded when import arcpy is being called.  Try adding the following just before you call the 'import arcpy' to see if that helps. (this moves FME's python libs to the end of the path so that ArcGIS's are found first.

import sys
sys.path.append(sys.path.pop(0))
sys.path.append(sys.path.pop(0))

If the above doesn't help, you are using FME 64bit (with background processing enabled in ArcGIS), and you are using FME's python interpreter try locating your ArcGIS site-packages libraries... and add this to the path (if not there), ensuring it comes before FME's /<install folder>/python/python27.  

As an example, for a recent customer's 64bit FME system we had to have 

`C:\apps\Python2764\ArcGISx6410.2\lib\site-packages` 

in the PATH and come before 

`C:\Program Files\FME16494\/python/python27`

If none of this helps... please contact us at www.safe.com/support.

btw way this gets better in 2017 - and you shouldn't see this problem

Userlevel 4

Yes both great suggestions above.  Do try @david_r suggestion (setting the workspace) - you'll likely need quotes around the workspace name. 

I helped a customer not long ago where the error message returned was nothing related to the problem.   @mmccart refers the the python interpreter... which is a good check.  Are you using FME's default or Esri's?

I'll also mention another possible consideration.  We made a change in FME 2016.1 that does change what python libraries are loaded in some situations.   

Try reviewing the PATH using the PythonCaller to see what is there for python folders.  There is a chance that a different set of libraries is being loaded when import arcpy is being called.  Try adding the following just before you call the 'import arcpy' to see if that helps. (this moves FME's python libs to the end of the path so that ArcGIS's are found first.

import sys
sys.path.append(sys.path.pop(0))
sys.path.append(sys.path.pop(0))

If the above doesn't help, you are using FME 64bit (with background processing enabled in ArcGIS), and you are using FME's python interpreter try locating your ArcGIS site-packages libraries... and add this to the path (if not there), ensuring it comes before FME's /<install folder>/python/python27.  

As an example, for a recent customer's 64bit FME system we had to have 

`C:\apps\Python2764\ArcGISx6410.2\lib\site-packages` 

in the PATH and come before 

`C:\Program Files\FME16494\/python/python27`

If none of this helps... please contact us at www.safe.com/support.

btw way this gets better in 2017 - and you shouldn't see this problem

I can confirm that we've also had this exact issue. In the end I wrote a small function to re-order the PythonPath, that we call before importing arcpy:

 

 

def order_python_path(fme_first):
    # Reorders the PythonPath to either have all the FME libraries first or last
    import sys
    ppath = set(sys.path) # Remove any duplicate entries
    fme_items = [x for x in ppath if x.upper().find('FME') > -1 and x <> '']
    other_items = [x for x in ppath if x.upper().find('FME') == -1 and x <> '']
    if fme_first:
        sys.path = fme_items + other_items
    else:
        sys.path = other_items + fme_items
    return sys.path

 

Userlevel 2
Badge +19

Yes both great suggestions above.  Do try @david_r suggestion (setting the workspace) - you'll likely need quotes around the workspace name. 

I helped a customer not long ago where the error message returned was nothing related to the problem.   @mmccart refers the the python interpreter... which is a good check.  Are you using FME's default or Esri's?

I'll also mention another possible consideration.  We made a change in FME 2016.1 that does change what python libraries are loaded in some situations.   

Try reviewing the PATH using the PythonCaller to see what is there for python folders.  There is a chance that a different set of libraries is being loaded when import arcpy is being called.  Try adding the following just before you call the 'import arcpy' to see if that helps. (this moves FME's python libs to the end of the path so that ArcGIS's are found first.

import sys
sys.path.append(sys.path.pop(0))
sys.path.append(sys.path.pop(0))

If the above doesn't help, you are using FME 64bit (with background processing enabled in ArcGIS), and you are using FME's python interpreter try locating your ArcGIS site-packages libraries... and add this to the path (if not there), ensuring it comes before FME's /<install folder>/python/python27.  

As an example, for a recent customer's 64bit FME system we had to have 

`C:\apps\Python2764\ArcGISx6410.2\lib\site-packages` 

in the PATH and come before 

`C:\Program Files\FME16494\/python/python27`

If none of this helps... please contact us at www.safe.com/support.

btw way this gets better in 2017 - and you shouldn't see this problem

 

Thanks for all the answers provided! I will let you know if they work as soon as I test them (the priority of other projects keeps me away from this one).

With FME 2016.1:

import sys

 

sys.path.append(sys.path.pop(0))

 

sys.path.append(sys.path.pop(0))

as SteveAtSafe suggested, solved the problem to access SDE FeatureClasses.

Reply