span8
span4
FME_BEGIN_TCL设置gTranslationStartTime [时钟格式[时钟秒] FME_END_TCL放\ “翻译开始时间:$ gTranslationStartTime \ nTranslation结束时间:时钟格式[时钟秒] \”
FME_END_TCL PROC最后{} {\全球立即将fme_status;\如果{$立即将fme_status == “1”} {\放\ “翻译成功\”;\}其他{\放\ “翻译没有成功\”;\};\};这同样的例子也可以写成不使用程序:
FME_END_TCL如果{$立即将fme_status == “1”} {\放\ “翻译成功\”;\}其他{\放\ “翻译没有成功\”;\}
#在该映射文件用于设置目的地#数据集目录中的宏存在是DestDataset。DWG_DATASET“$(DestDataset)”#源在Tcl脚本在这个翻译结束运行。#脚本存储在同一目录此映射文件。FME_BEGIN_TCL源$(FME_MF_DIR_UNIX)/backup.tcl;备份{$(DestDataset)}
PROC备份{文件名} {{IF [文件存在$文件名]} {文件复制-force $文件名$ filename.bak}}
#来源在Tcl脚本在这个翻译结束运行。#脚本存储在同一目录此映射文件。FME_END_TCL源$(FME_MF_DIR_UNIX)/tryAnother.tcl
集OUTPUTFILE [打开C:/temp/status.txt W +]如果{$立即将fme_status == “1”} {$放OUTPUTFILE “翻译成功”}其他{$放OUTPUTFILE “转换失败 - 跑交替翻译” EXEC FME.EXE alternateTranslation.fme 2> NUL:}关闭$ OUTPUTFILE
FME_LogMessage fme_inform {喜戴尔在线}
从pyfme进口*日志= FMELogfile()log.log( “你好”)
FME_END_TCL set outputFile [open $FME_LogFileName a] ; \ puts $outputFile {}; \ puts $outputFile {Writing some stuff at the end}; \ puts $outputFile {}; \ close $outputFile;
#设置映射文件ID,以便Tcl的定稿程序#“知道”映射文件正在运行MAPPING_FILE_ID形状到AutoCAD#日志中的所有消息编号,以便以后可以拉出来只有那些我们感兴趣的是#其中。LOG_MESSAGE_NUMBERS是#来源Tcl脚本的在这个翻译结束运行。#脚本存储在同一目录此映射文件。FME_END_TCL源$(FME_MF_DIR_UNIX)/tclFinalization.tcl
#打开写出来的翻译统计文件设置OUTPUTFILE [打开C:/temp/stats_out.txt W +]#检查翻译状态和输出,如果{$立即将fme_status ==“1”}所需的信息{$放OUTPUTFILE“翻译是成功的”}其他{$放OUTPUTFILE‘转换失败’看跌期权$ OUTPUTFILE‘错误信息是:$ FME_FailureMessage’};放$ OUTPUTFILE“翻译摘要$ FME_MappingFileId”#输出的特征的数量读\每特征类型写入“#输出在映射文件使用MAPPING_FILE_ID放$ OUTPUTFILE独特映射文件标识符集”。看跌期权$ 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
本例使用外部脚本插入翻译的活动记录到使用TclODBC包的数据库。在这个例子中,一个Access数据库中创建(如果需要),并与一排用于填充每个翻译这就完成。
TclODBC
到FME环境中使用TclODBC,请按照下列步骤操作:
FME_END_TCL源$(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源$(FME_MF_DIR_UNIX)/recordTranslationOracle.tcl
#========================================================================= ## recordTranslationOracle.tcl ##这个脚本使用记录的#包Oratcl翻译的执行。这个例子包括用于存储翻译结果创建#XLATION_RESULTS表。#每个翻译运行一个行被插入到表中。包装要求Oratcl#=========================================================================#登录设置loginHandle Oracle服务组的用户名斯科特设定密码虎集服务阿米达拉[oralogon $的用户名/ $密码@ $服务]#=========================================================================#确定,如果我们想记录结果向xlation_results表存在一套tableExists没有设置statementHandle [oraopen $loginHandle] orasql $ statementHandle “从USER_TABLES选择*在表格名= 'XLATION_RESULTS'”,而{[orafetch $ statementHandle -datavariable行] == 0} {集tableExists是}#=========================================================================#创建xlation_results表,如果我们需要,如果{$ tableExists == “不”} {$ orasql statementHandle“CREATE TABLE XLATION_RESULTS(MappingFileID VARCHAR(50),开始时间TIMESTAMP,结束时间TIMESTAMP,CPUTIME FLOAT,XlationSuccessful 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
©2020安全亚搏在线软件公司|法律