Skip to main content
Question

Call a FME workbench from python with dynamic arguments?

  • November 27, 2020
  • 2 replies
  • 54 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. 

 

 

 

2 replies

hkingsbury
Celebrity
Forum|alt.badge.img+55
  • Celebrity
  • November 29, 2020

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


david_r
Celebrity
  • 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

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings