Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Line by line execution
#1
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 = [font="Calibri",sans-serif]'C:\FME\Project_1.fmw'[/font]
parameters = {}
parameters['SourceDataset_ACAD'] =[font="Calibri",sans-serif]'C:\AutoCAD\Project_1.dwg'[/font]
parameters['DestDataset_OGCKML'] =[font="Calibri",sans-serif]'C:\Maps_KMZ\Project_1.kmz'  [/font]

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. If so, how to do it. I don`t have much Python experience so if you can help me directly with the code that would be fantastic.

Disregard this [font ...etc] stuff , NOT a part of the code, I cannot figure out how to delete that from the code, this is so confusing pasting code in here.


Thank you very much for your help!
Reply
#2
import os.path
from glob import glob

# glob(pattern) returns all files according to the pattern
for dwg in glob("/path/*.dwg"): # the path can be set in Unix style regardless of the OS
    in_file = os.path.abspath(dwg) # get the absolute path of a file. For example: 'C:\AutoCAD\Project_1.dwg'

    # os.path.splittext(file_name) separate the the file name from the extension and you get ['my_file', '.txt']
    out_file = "{}{}".format(os.path.splittext(in_file)[0], '.kmz')

    # os.path.join(path, file_name) joins the path with the file name properly formated with '/'
    out_full_path = os.path.join('C/Maps_KMZ', out_file)

    # Parameters
    parameters['SourceDataset_ACAD'] =[font="Calibri",sans-serif]"{}".format(in_file)[/font]
    parameters['DestDataset_OGCKML'] =[font="Calibri",sans-serif]"{}".format(out_full_path)  [/font]

    # and so on
    # ...
Something like this should work
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Line graph with two superimposed lines sawtooth500 4 329 Apr-02-2024, 08:56 PM
Last Post: sawtooth500
  How to add multi-line comment section? Winfried 1 208 Mar-24-2024, 04:34 PM
Last Post: deanhystad
  break print_format lengthy line akbarza 4 369 Mar-13-2024, 08:35 AM
Last Post: akbarza
  Reading and storing a line of output from pexpect child eagerissac 1 4,253 Feb-20-2024, 05:51 AM
Last Post: ayoshittu
  coma separator is printed on a new line for some reason tester_V 4 490 Feb-02-2024, 06:06 PM
Last Post: tester_V
  problem with spliting line in print akbarza 3 386 Jan-23-2024, 04:11 PM
Last Post: deanhystad
  Unable to understand the meaning of the line of code. jahuja73 0 307 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  Receive Input on Same Line? johnywhy 8 724 Jan-16-2024, 03:45 AM
Last Post: johnywhy
  Reading in of line not working? garynewport 2 839 Sep-19-2023, 02:22 PM
Last Post: snippsat
  'answers 2' is not defined on line 27 0814uu 4 735 Sep-02-2023, 11:02 PM
Last Post: 0814uu

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020