Published Parameter use within a Startup or Shutdown Script
From fmepedia
These are examples of Startup and Shutdown Scripts that make use of Published Parameters.
Example 1
Example 1: FTP results of a translation as soon as translation ends
In some situations, it is useful take the results of your translation and FTP them somewhere.
Here’s an FME_END_TCL script (and I’ve attached a workspace with this) that does just that – note that it leverages the DestDataset macro (which was published in the workspace as the location for the output) to find the output file for ftp purposes:
package require ftp puts [array names FME_MacroValues];
puts "Uploading $FME_MacroValues(DestDataset)" set server "something.anotherthing.com" set user "ACCOUNTNAMEGOESHERE" set passwd "PASSWORDGOESHERE" set conn [::ftp::Open $server $user $passwd] puts "step 2" ::ftp::Cd $conn outgoing/services puts "step 3" ::ftp::List $conn * puts "step 4" ::ftp::Put $conn $FME_MacroValues(DestDataset) ::ftp::Close $conn puts "Upload Complete"
Of course, in production you’d wrap the various ::ftp::.. things in “catch”es so you could flag errors appropriately.
Example 2
Example 2: Fetch a URL into an attribute
For the screenscrapers amongst you, this little fragment of Tcl:
package require http puts [http::geturl http://www.google.ca (http::data) ]
Shows how you can grab a URL and use its contents (here I’m just printing it out, but it could easily go into an attribute if it was being invoked in an @Tcl). I liked the idea so much we wrapped it up into a new transformer “URLFetcher”, which is part of FME as of build 4300. An example is attached (and the underlying mapping file code is pasted below in case you’d like to use the technique in a mapping file or Tcl script in another way.)
Tcl2 proc URLFETCHER_fetch { url } { \
package require http; \
FME_SetAttribute _url_contents {}; \
if { [catch {FME_SetAttribute _url_contents \
[ http::data [set token $url (http::geturl) ] ] \
} errorMsg \
] \
} { \
catch {http::cleanup $token}; \
if {No == {Yes}} { \
FME_LogMessage fme_error \"Error retrieving URL `$url' in transformer URLFETCHER: $errorMsg\"; \
} else { \
error \"Error retrieving URL `$url' in transformer URLFETCHER: $errorMsg\"; \
} \
} else { \
puts $token; \
catch {http::cleanup $token}; \
} \
}
FACTORY_DEF * TeeFactory \
FACTORY_NAME URLFETCHER \
INPUT FEATURE_TYPE CREATOR_CREATED_1 \
OUTPUT FEATURE_TYPE URLFETCHER_OUTPUT \
@Tcl2("URLFETCHER_fetch {@Value(URL)}")
You can read more about using http inside of Tcl at http://wiki.tcl.tk/1303. Note – one issue I did find and we will document as a known issue is that if there is an error retrieving the URL, it seems that the FME process itself will hang on exit.
Example 3
Example 3: Check in the registry for a setting
Here’s an example where you check the registry to see what version ArcGIS is there, presumably to do some kind of nice error message or ?? if it isn’t.
proc getArcGISVersion {} {
package require registry 1.0
set path {HKEY_LOCAL_MACHINE\SOFTWARE\ESRI\ArcInfo\Desktop\8.0}
set value [registry get $path {RealVersion}]
return $value
}
set ArcGISVersion [getArcGISVersion]
As usual with FME, the possibilities are endless. I think with this you could turn FME into a webserver if you felt like it, so go ahead and have some fun!
