0

I have a Python script that I run in ArcGIS Desktop 10.2. I also have an FME workbench I use in part of the same process. I currently have to run half of the script, switch to FME then run the other half. I would like my script to call the FMW.

At present I'm trying:

cmd = '"C:\\Program Files\\FME201864bit\\fme.exe" "W:\\Entity\\ABZ\\Operations & Geosciences\\GSR\\GIS Data\\_Common-Data\\_Resources\\Tools\\MigMapCountourFiller.fmw" --SourceDataset_ESRISHAPE "\\\\main.glb.corp.local\\Data\\EP\\EMEA\\GB\\Group\\Data\\GIS\\Explo\\NewVentures\\Opportunities\\Winterton2018\\Migration\\2018-02-14_CarbMigFiles\\contours_l_1m.shp" --DestDataset_ESRISHAPE "\\\\main.glb.corp.local\\Data\\EP\\EMEA\\GB\\Group\\Data\\GIS\\Explo\\NewVentures\\Opportunities\\Winterton2018\\Migration\\2018-02-14_CarbMigFiles"'
os.system(cmd)

this is returning:

'C:\Program' is not recognised as an internal or external command, operable grogram or batch file. The system cannot find the path specialised.

I can see that the problem is the space between program and files but I dont understand why its ignoring my quotes.

I see there are multiple ways of accessing command line from python and that there is also FMEobjects but I haven't managed to get them to work. Am I trying the right thing but getting it wrong or should I be using a completely different method.

  • By "a python script that I run in ArcGIS Desktop", do you mean a Python Script tool in a standard TBX toolbox, or a Python Toolbox PYT tool, or something else? In any event what code snippet are you using to try and run the two lines that you appear to have copy/pasted from your actual code? – PolyGeo Jun 20 '18 at 18:43
  • Ultimately it will end up in a python Toolbox but at the moment I'm just trying to run these two lines by themself from python console in ArcMap – whatahitson Jun 21 '18 at 9:54
3

Managing all arguments in a single string is a debugging hell.

You would be better off using subprocess and having your arguments in a tidy list structure.

import os
import subprocess

args = [r"C:\FME\fme.exe", "version"]
subprocess.Popen(args)

Output:

FME 2018.0.0.0 (20180308 - Build 18284 - WIN64)

Your arguments would obviously be different. In my case, I just want to make sure the fme.exe is called with a single argument.

As Mark pointed out, your other option is to use fmeobjects which would give you ability to call your workbenches. The minimal working code:

import sys
sys.path.append(r'C:\FME\fmeobjects\python27')

#----------------------------------------------------------------------
def buffer_single_shapefile_diff_param_values():  
    try:
        wkspc_path = r"C:\FMEWorkbenches\BufferForSameShapefile.fmw"

        wkspc = fmeobjects.FMEWorkspaceRunner()
        for dist in xrange(100,200,25):
            wkspc.runWithParameters(wkspc_path,
                                    {"Output_buffered_name":"Buffered_{0}m".format(dist),
                                     "OFFSET":"{0}".format(dist)})

    except fmeobjects.FMEException, err:
        print "FMEException: %s" % err
        sys.exit(1)

buffer_single_shapefile_diff_param_values()
0

Although what you are trying should work (I don't have enough Python knowledge to debug quotes) I think the better solution is to use FME Objects.

Check out the documentation for the FMEObjects API. In particular you're looking for a method called fmeobjects.FMEWorkspaceRunner and FMEWorkspaceRunner.run(workspace)

You say you couldn't get FME Objects to work. Was there a particular issue or error? Were you using this method or something else?

  • I add the fmeobjects module by entering import sys ... sys.path.append(r'C:\Program Files\FME201864bit\fmepython27') but then whenever I type FME objects I get NameError: name 'fmeobjects' is not defined – whatahitson Jun 21 '18 at 7:28
  • 1
    I think I've got it working now – whatahitson Jun 21 '18 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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