0

I couldn't fine solution for this question using search option so my question is: I have a script that does the job but only for one file. Just to explain what`s going on here:

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

import fmeobjects 
runner = fmeobjects.FMEWorkspaceRunner()
workspace = 'C:\FME\Project_1.fmw'

parameters = {}
parameters['SourceDataset_ACAD'] ='C:\AutoCAD\Project_1.dwg'
parameters['DestDataset_OGCKML'] ='C:\Maps_KMZ\Project_1.kmz'  
runner.runWithParameters(workspace, parameters)

try:
    # Run Workspace with parameters set in above directory
    runner.runWithParameters(workspace, parameters)
    # or use promptRun to prompt for published parameters
    #runner.promptRun(workspace)
except fmeobjects.FMEException as ex:
    # Print out FME Exception if workspace failed
    print ex.message
else:
    #Tell user the workspace ran
    print('The Workspace is ran successfully'.format(workspace))

runner = None

This script executes FMW file that does conversion from AutoCAD DWG (C:\AutoCAD) to KMZ file and stores it in C:\Maps_KMZ folder. Now, I need to do the same thing for about 20-ish FME files that are in the same source folder. Is it possible to execute each file at the time and add specific time frame between two executions let`s say 2 minute pause between them, because I can not run 2 or more conversions at the same time, it would crash Windows.

Thank you very much for your help!

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • Put the file paths in a list, put the processing in a function, iterate over the list and pass the filepath(s) to the function, put a delay at the bottom of the loop. – wwii Dec 11 '17 at 18:38
  • 1
    Notice how @wwii describes the steps in words. I suggest you flesh out his suggestions in more detail primarily using English, or whichever language you are most comfortable with. When you have a good verbal description of the steps needed to solve the problem then you can start to translate it into Python. – Code-Apprentice Dec 11 '17 at 18:42

1 Answers1

0

I suggest that you modify your script to use command line arguments. You can either use sys.argv directly for a very simple interface or the parseargs module for more complex options.

You can write the interface to accept individual files names or directory names. To traverse the files of a directory, look at os.walk().

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • or the `click` library for a simple interface *and* complex options :) – juanpa.arrivillaga Dec 11 '17 at 18:39
  • @juanpa.arrivillaga I am not familiar with click. Thanks for the suggestion. – Code-Apprentice Dec 11 '17 at 18:40
  • Thank you guys for quick replies ..... the problem is that I have no much Python experience. – user7380301 Dec 11 '17 at 18:50
  • I suggest you google "python command line arguments" or "python parseargs" to find some documentation and tutorials. – Code-Apprentice Dec 11 '17 at 19:51
  • "the problem is that I have no much Python experience" From my point of view, that is an opportunity, not a problem. – Code-Apprentice Dec 11 '17 at 19:52
  • As a computer programmer and software engineer, learning to read technical documentation is critical. After you have done some reading, then Stack Overflow is a great resource to ask questions about the parts that are confusing. Just be sure to ask specific questions, including quotes from your reading that you do not understand. – Code-Apprentice Dec 12 '17 at 18:06