Hi
It tok some time to find out how to do this but now, I do it a lot. I am now
running up to 4 different fme mapping files / tcl scripts to do one
translation. some of these I use to run my main mapping file in a loop /
batch mode, and one is to get different paramters for this translation like
the bounding box and a cutting polygon.
As Mark points out, The "2> NUL:" part of the command is to get rid of the
output from the translation - all the log stuff - otherwise tcl will try to
execute it as a command, and then abort with a error.
In tcl the trick is to build the command as a list and then run this list
with a eval exec command - se the function below. the catch is to check if i
got an error and the stop the translation.
In the slave mapping file I have a tcl function writing the parameters to a
textfile all my bounding box parametes a written as 'MACRO name value', and
the cutting polygon is written to a ffs file.
To get the parameters back into the main mapping file you have to use
include as you write, but you have to use more than one. In the main mapping
file I run the tcl command using the INCLUDE [ script ... ], and after this
I have a INCLUDE file.fmi to include the file with the macros. The cutting
polygon is imported using a ReccordFactory.
The reason to use the above syntax is that the slave mapping file is
executet while the main mapping file is parsed. We could alsoe use
FEM_BEGIN/END_TCL or Tcl2 to do the same but then we would could not use the
INCLUDE file.fme, as these commands are executed after the parsening of the
main mapping file and we would not be able to write MACRO' back into the
mapping file.
By using Tcl2 we could on the other hand place values in global tcl
variables, and these values we could then access using a Tcl2 function, this
way we can create an error in the running mapping file if the slave is
aborted with an error.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
This is the tcl function I use.
proc getCutter {polyForm polyCoordSys polyFileName polyBuffer usr dim } {
set mFile $::gsPath2App/FMI/2CUTTER/2CUTTER.FME
getParamFileName $polyFileName
set paramFile $newPFN
# note how we can write macros into the mapping file
puts "MACRO paramFile $paramFile"
lappend cmd fme.exe
lappend cmd $mFile
lappend cmd --SourceFormat $polyForm
lappend cmd --SourceCoordSys $polyCoordSys
lappend cmd --polyFileName $polyFileName
lappend cmd --polyBuffer $polyBuffer
lappend cmd --paramFile $paramFile
lappend cmd --usr $usr
lappend cmd --Dim $dim
lappend cmd 2> NUL:
# the trick is the command as a tcl list and the eval command
switch -- [ catch { eval exec $cmd } msg ] {
0 { puts "===> Oversættelse gik godt."
}
default { puts "===> Oversættelse gik ikke godt, fejl er:\n$msg"
abort "ERROR: Fejl under oversættelse af skærepolygon"
}
}
return
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
and this is the mapping file fragment running and including
INCLUDE [ source $env(LDS_HOME)/TCL/getCutter.tcl ;
\
getCutter $(polyFormat) $(polyCoordSys) {$(polyFileName)}
$(polyBuffer) $(usr) $(Dim) ]
INCLUDE "$(cutterRoot)\$(paramFile).FMI"
NB In last years MVP contest you can find a exampel of some of this, look
for just4fun.fme I cant remember the number.
Peter Laulund
>From: "mark2atsafe" <[EMAIL PROTECTED]>
>Reply-To: [email protected]
>To: [email protected]
>Subject: [fme] Re: execute fme script from another fme script with new
>envelope parameters
>Date: Tue, 06 Dec 2005 17:29:31 -0000
>
>Hi,
>One suggestion I have (and I concede there will be other methods) is
>to use the post processing TCL function.
>
>This page...
>http://www.fmepedia.com/index.php/Pre_and_Post_Processing_with_TCL_FAQ
>...has some FAQs on the subject.
>
>You can call one FME mapping file from the first using this. The
>approx syntax would be...
>FME_END_TCL exec fme.exe anotherTranslation.fme 2> NUL:
>
>To pass values through I would use macros. The first thing I'd try
>would be to create a macro from your coords and pass them to a macro
>in the new mapping file. I'd try it like this...
>FME_END_TCL exec fme.exe anotherTranslation.fme --FileTwoLLXMacro
>$(FileOneLLXMacro) 2> NUL:
>
>As I said, I'm sure other folk will have other suggestions, but this
>is the first idea that came to me and I think it ought to work OK.
>
>Regards,
>
>Mark
>
>Mark Ireland, Product Support Engineer
>Safe Software Inc. Surrey, BC, CANADA
>[EMAIL PROTECTED] http://www.safe.com
>Solutions for Spatial Data Translation, Distribution and Access
>
>--- In [email protected], "Michael Pinter" <[EMAIL PROTECTED]> wrote:
> >
> > Hello group,
> >
> > In fme file A, I calculate four coordinates! These four coordinates
> > should be my search envelope (LLX;LLY;URX;URY) in fme file B.
> > How can I do this?
> > How can I load a mapping file from a mapping file with parameters?
> > I tried it with INCLUDE but it doesn't work.
> >
> > Any advice would be helpful!
> > michp
> >
>
>
>
>
>
>
>Get the maximum benefit from your FME, FME Objects, or SpatialDirect via
>our Professional Services team. Visit www.safe.com/services for details.
>Yahoo! Groups Links
>
>
>
>
>
>
_________________________________________________________________
Log på MSN Messenger direkte på nettet http://webmessenger.msn.com/
Get the maximum benefit from your FME, FME Objects, or SpatialDirect via our
Professional Services team. Visit www.safe.com/services for details.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/fme/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/