span8
span4
span8
span4
fme_begin_tcl set gtranslationstarttime [时钟格式[时钟秒]] fme_end_tcl puts \“翻译开始时间:$ gtranslationstarttime \ ntranslation结束时间:[时钟格式[时钟秒]] \”
fme_end_tcl proc最后{} {\ global fme_status;\如果{$ fme_status ==“1”} {\ puts \“翻译成功\”;\}别的{\ puts \“翻译没有成功\”;\};\};This same example could also be written without using a procedure:
FME_END_TCL if {$FME_Status == "1"} { \ puts \"Translation was successful\"; \ } else { \ puts \"Translation was NOT successful\"; \ }
# The macro being used in this mapping file to set the destination # dataset directory is DestDataset. DWG_DATASET "$(DestDataset)" # Source in the Tcl script to run at the conclusion of this translation. # The script is stored in the same directory as this mapping file. FME_BEGIN_TCL source $(FME_MF_DIR_UNIX)/backup.tcl; backup {$(DestDataset)}
proc backup {filename} { if {[file exists $filename]} { file copy -force $filename $filename.bak } }
#源Tcl脚本运行的结论n of this translation. # The script is stored in the same directory as this mapping file. FME_END_TCL source $(FME_MF_DIR_UNIX)/tryAnother.tcl
set outputFile [open c:/temp/status.txt w+] if { $FME_Status == "1" } { puts $outputFile "Translation was successful" } else { puts $outputFile "Translation failed -- running alternate translation" exec fme.exe alternateTranslation.fme 2> NUL: } close $outputFile
FME_LogMessage fme_inform {hi dale inline }
来自pyfme import * log = fmelogfile()log.log(“howdy”)
FME_END_TCL set outputFile [open $FME_LogFileName a] ; \ puts $outputFile {}; \ puts $outputFile {Writing some stuff at the end}; \ puts $outputFile {}; \ close $outputFile;
# Set a mapping file id so that the Tcl finalization procedure # "knows" which mapping file was being run MAPPING_FILE_ID Shape to AutoCAD # Log all the message numbers so that we can later pull out only those # we are interested in. LOG_MESSAGE_NUMBERS yes # Source in the Tcl script to run at the conclusion of this translation. # The script is stored in the same directory as this mapping file. FME_END_TCL source $(FME_MF_DIR_UNIX)/tclFinalization.tcl
#打开要写出翻译stats set outputfile [打开c:/temp/stats_out.txt w +]#检查转换状态并输出所需邮件是否{$ fme_status ==“1”} {puts $ outputfile“。翻译是成功的“}} {puts $ outputfile”翻译失败“puts $ outputfile”错误消息是:$ fme_failuremessage“};Puts $ OutputFile“#输出使用mapping_file_id在映射文件中设置的唯一映射文件标识符为$ fme_mappefiled的$ outputfile”翻译摘要“#输出每个要素类型读取的功能数读取。Puts $ Outputfile“----------------------------------------------------------------------------------------------------------------------------------" puts $outputFile " Features read summary" puts $outputFile "-------------------------------------------------------------------------------" # Loop through a sorted listed of the feature types that were read, and output the # count for each one set formatSpec "%-65s: %12s" foreach featType [lsort [array names FME_FeaturesRead]] { puts $outputFile [format $formatSpec $featType $FME_FeaturesRead($featType)] } puts $outputFile "-------------------------------------------------------------------------------" puts $outputFile [format $formatSpec "Total Features Read" $FME_TotalFeaturesRead]; puts $outputFile "-------------------------------------------------------------------------------" puts $outputFile "" puts $outputFile "-------------------------------------------------------------------------------" puts $outputFile " Features Written summary" puts $outputFile "-------------------------------------------------------------------------------" # Loop through a sorted listed of the feature types that were written, and output the # count for each one foreach featType [lsort [array names FME_FeaturesWritten]] { puts $outputFile [format $formatSpec $featType $FME_FeaturesWritten($featType)] } puts $outputFile "" puts $outputFile "-------------------------------------------------------------------------------" puts $outputFile [format $formatSpec "Total Features Written" $FME_TotalFeaturesWritten] puts $outputFile [format $formatSpec "Total Coordinates Written" $FME_TotalCoordinates] puts $outputFile "-------------------------------------------------------------------------------" puts $outputFile "" # Look for any lines in the logfile that were warnings, and output a count of them to # the summary file. Also, check if there was any "unexpected input remover" # statistics line and report a non-zero count if there was (this may happen # when workbench generated mapping files are run against input datasets # with different feature types than those that were expected) # And also fish out the system status log message (which is #246014) and copy # it into the output file set logFileExists [file exists $FME_LogFileName] set warnings 0 if {$logFileExists} { set logFile [open $FME_LogFileName r] while {[gets $logFile line] >= 0} { if {[regexp {WARN} $line]} { incr warnings } elseif {[regexp {#246014} $line]} { puts $outputFile "-------------------------------------------------------------------------------" puts $outputFile $line puts $outputFile "-------------------------------------------------------------------------------" puts $outputFile "" } elseif {[regexp {Unexpected Input Remover} $line]} { set totalFeatures 0 set acceptedFeatures 0 set rejectedFeatures 0 set line [regsub {^.*Unexpected} $line {Unexpected}] catch {scan $line "Unexpected Input Remover(TestFactory): Tested %d input features -- %d features passed, %d features failed." totalFeatures acceptedFeatures rejectedFeatures} if {$rejectedFeatures > 0} { puts $outputFile "---------------------------------------------------------------------------- ---" puts $outputFile [format $formatSpec "Features with Unexpected Feature Types" $rejectedFeatures] puts $outputFile "---------------------------------------------------------------------------- ---" puts $outputFile "" } } } close $logFile } puts $outputFile "-------------------------------------------------------------------------------" puts $outputFile [format $formatSpec "Logfile $FME_LogFileName Warnings" $warnings] puts $outputFile "-------------------------------------------------------------------------------" puts $outputFile "" puts $outputFile "-------------------------------------------------------------------------------" puts $outputFile [format $formatSpec "Total Elapsed Time (seconds)" $FME_ElapsedTime] puts $outputFile [format $formatSpec "Total CPU Time (seconds)" $FME_CPUTime] puts $outputFile "-------------------------------------------------------------------------------" puts $outputFile "" # And close the file close $outputFile
This example uses an external script to insert a record of the translation's activity into a database using the TclODBC package. In this example, an Access database is created (if necessary)and populated with a row for each translation that completes.
TclODBC
要在FME环境中使用TCLODBC,请按照下列步骤操作:
FME_END_TCL source $(FME_MF_DIR_UNIX)/recordTranslationODBC.tcl
#=================================================.======================== # # recordTranslationODBC.tcl # # This script records the execution of a translation using # the TclODBC package. This example includes the creation of the # Access database and table for storing the translation results. # One row for each translation run is inserted into the table. # Note that for an acutal production system the "puts" statements # would be removed. package require tclodbc # ========================================================================= # # Set up some variables that are used within to create and connect # to the database via ODBC set driver "Microsoft Access Driver (*.mdb)" set dbfile c:/translations.mdb set dsn XLATION # ========================================================================= # Create the database if it isn't already there. We wouldn't do this if the # database was a server-based one, but for this example we're just using Access. if {![file exists $dbfile]} { puts "Creating database $dbfile" database configure config_dsn $driver [list "CREATE_DB=\"$dbfile\"General"] } else { puts "Using existing database $dbfile" } # ========================================================================= # Make an ODBC datasource for this database, and connect to it # First always remove the DSN if it was there already. If we were # using ODBC to connect to a "real" database, then we'd just assume # the DSN is already valid catch {database configure remove_dsn $driver "DSN=$dsn"} database configure add_dsn $driver [list "DSN=$dsn" "DBQ=$dbfile"] database db $dsn # ========================================================================= # Create the table we want to insert into if it wasn't there already if {[llength [db tables XLATION_RESULTS]] == 0} { puts "Creating XLATION_RESULTS table in database $dbfile" db "CREATE TABLE XLATION_RESULTS ( MappingFileID VARCHAR(50), StartTime TIMESTAMP, EndTime TIMESTAMP, CpuTime DOUBLE, Successful CHAR(3), NumFeatures INTEGER)" } else { puts "XLATION_RESULTS table present in database $dbfile" } # ========================================================================= # All of that was just setup, now we actually can insert our row, # commit it, and disconnect from the datasource set Success yes if {$FME_Status == 0} {set Success no} db "INSERT INTO XLATION_RESULTS (MappingFileID, StartTime, EndTime, CpuTime, Successful, NumFeatures) VALUES ('$FME_MappingFileId', \{ts '$FME_StartingTimeStamp'\}, \{ts '$FME_EndingTimeStamp'\}, $FME_CPUTime, '$Success', $FME_TotalFeaturesWritten)" db commit db disconnect # ========================================================================= # If you were connecting to a server-based database, you probably # would NOT remove the ODBC DSN at the end. But since we were file based # we will remove it database configure remove_dsn $driver "DSN=$dsn"
This example uses an external script to insert a record of the translation's activity into an Oracle database using the Oratcl package.
oratcl.
要在FME环境中使用OratCL,请按照下列步骤操作:
FME_END_TCL source $(FME_MF_DIR_UNIX)/recordTranslationOracle.tcl
#=================================================.======================== ## RecordTranslationOracle.TCL ##此脚本记录使用#oratcl包的翻译执行。此示例包括创建#XLation_Results表以存储转换结果。#每行为每个转换运行插入到表中。包装要求oratcl#========================================================================= ##登录Oracle服务集用户名斯科特集密码Tiger Set Service Amidala Set LoginHandle [oralogon $ username / $密码@ $服务]#=========================================================================#确定是否xlation_results表我们希望记录结果,存在设置表交换者没有set stentical handle [oraopen $loginHandle] Orasql $ StemendHandle“从user_tables选择*,其中table_name ='xlation_results'”while {[orafetch $ stinemendhandle -datavariable行] == 0} {set tabeExists是}#=========================================================================#如果我们需要{$ tableExstress ==“no”} {orasql $ stinementhandle“创建表xlation_results(mappefiled varchar(50),starttime timestamp,Endtime Timestamp,则创建Xlation_Results表Cupputime Float,Xlationsucesful Char(3),NumFeatures Integer)“}#=========================================================================#插入 translation results into the table set Success yes if {$FME_Status == 0} {set Success no} orasql $statementHandle "INSERT INTO XLATION_RESULTS (MappingFileID, StartTime, EndTime, CpuTime, XlationSuccessful, NumFeatures) VALUES ('$FME_MappingFileId', timestamp '$FME_StartingTimeStamp', timestamp '$FME_EndingTimeStamp', $FME_CPUTime, '$Success', $FME_TotalFeaturesWritten)" -commit # ========================================================================= # Shut down the statement handle oraclose $statementHandle # ========================================================================= # Logout of our oracle service oralogoff $loginHandle
Published Parameter use within a Startup or Shutdown Script
Extract Geodatabase Coded Domain Definitions
使用Python启动/关闭脚本或PythonCaller与Arcpy执行地理处理
Example Workflow using FME, Python and Oracle
How to log out after running a translation (Windows OS)
Transfer Workspace File Output Using SFTP (FME Server 2015 and below)
© 2019 Safe Software Inc |Legal