Skip to main content
Question

Call a FME workbench from python with dynamic arguments?

  • November 27, 2020
  • 2 replies
  • 65 views

alfons
Contributor
Forum|alt.badge.img+7

Hello, 

 

I would like to run a workbench via Python. The workflow within the script is always the same. Only the input and output directories change.

For this purpose I have written a function and call it accordingly.

def fme_workbench(workbench, argument):
    FME_command = '"C:\Program Files\\FME\\fme.exe" ' + workbench + ' ' + argument
    result = subprocess.Popen(FME_command)
    result.wait()
argument = '--Name_Veg4m_umhuellend "' + str(kachelnummer) + '_veg4m_hull" --Name_Veg4m_Loecher "' + str(kachelnummer) + '_veg4m_holes" --SourceDataset_ESRISHAPE_5 "' + os.path.join(output_dir, str(Mission), 'Lidar_RAW', str(kachelnummer), 'Output\\*.shp') + '" --FEATURE_TYPES ""  DestDataset_ESRISHAPE "' + os.path.join(output_dir, str(Mission), 'Lidar_RAW', str(kachelnummer), 'Output') + '"'
                    fme_workbench(os.path.join(script_dir, 'EB_0_Aufbereitung_klassierte_Vegetation.fmw'), argument)

the following variables are dynamic and can change:

  • kachelnummer
  • Mission

 

calling the Workbench from Python works without problems. Only the dynamic variables are not considered. Thus the same data is always calculated, which was last calculated with the workbench, started directly from FME. My question now is, how do I define the Published Parameters in the script, so that it interprets the arguments provided from Python correctly. Unfortunately I cannot leave them empty - I get the error message "Parameter 'DestDataset_ESRISHAPE' must be given a value. 

 

 

 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

hkingsbury
Celebrity
Forum|alt.badge.img+63
  • Celebrity
  • 1632 replies
  • November 29, 2020

Any reason why you wouldn't use a parent/child workspace setup and use the WorkspaceRunner transformer?


david_r
Celebrity
  • 8394 replies
  • November 30, 2020

I agree with @hkingsbury​ , why not use the WorkspaceRunner?

Concerning running fme.exe from the command line, all the parameters must be in key/value pairs. This means that if you want to leave the value out, then you also need to skip the key. You need to resolve this manually in your Python code. Example:

arguments = []
if kachelnummer:
    arguments.append('--Name_Veg4m_umhuellend "{}_veg4m_hull"'.format(kachelnummer))
if some_other_parameter:
    arguments.append('--some_parameter "{}"'.format(some_other_parameter))
parameter = ' '.join(parameters)
# Finally call fme.exe + parameter