span8
span4
FME_BEGIN_TCL设置gTranslationStartTime[时钟格式[时钟秒]]\"转换开始时间:$gTranslationStartTime\nTranslation结束时间:[时钟格式[时钟秒]]\"
FME_END_TCL proc finally{}{\全局FME_Status;\如果{$FME_Status == "1"} {\ put \"翻译成功\";\} else {\ put \"翻译失败\";\};\};同样的例子也可以不使用过程:
如果{$FME_Status == "1"} {\ put \"翻译成功\";\} else {\ put \"翻译失败\";\}
这个映射文件中用来设置目标数据集目录的宏是DestDataset。DWG_DATASET "$(DestDataset)" # Source in the Tcl script to run at the conclusion of this translation.脚本存储在与这个映射文件相同的目录中。FME_BEGIN_TCL源(FME_MF_DIR_UNIX) / backup.tcl美元;备份{ $(DestDataset)}
proc backup {filename}{如果{[file exists $filename]} {file copy -force $filename.bak}}
在该转换结束时运行Tcl脚本中的源代码。脚本存储在与这个映射文件相同的目录中。$ (FME_MF_DIR_UNIX) / tryAnother.tcl FME_END_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导入*log=FMELogfile()log.log("您好")
FME_END_TCL设置outputFile[打开$FME_LogFileName a];\输入$outputFile {};\把$outputFile{写一些东西在后面};\输入$outputFile {};\接近outputFile美元;
设置映射文件id,以便Tcl最终处理过程“知道”正在将MAPPING_FILE_ID形状的映射文件运行到AutoCAD中,并将所有消息编号记录下来,以便稍后只提取我们感兴趣的那些映射文件。在转换结束时运行Tcl脚本中的LOG_MESSAGE_NUMBERS yes #源代码。脚本存储在与这个映射文件相同的目录中。$(FME_MF_DIR_UNIX)/ tclFinalization.tcl FME_END_TCL来源
#打开一个文件写的翻译数据集outputFile[打开c: / temp / stats_out.txt w +] #检查翻译状态和输出所需的消息如果{$ FME_Status = = " 1 "}{把$ outputFile“翻译是成功的”}其他{把$ outputFile“翻译失败”把美元outputFile“错误消息是:$ FME_FailureMessage "};输出映射文件中使用MAPPING_FILE_ID设置的唯一映射文件标识符把美元outputFile”- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -“把美元outputFile”特性总结“把美元outputFile”- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -“#循环排序列出的功能类型阅读,并输出每一组formatSpec "%-65s: %12s" foreach featType [lsort [array names FME_FeaturesRead]] {put $outputFile [format $formatSpec $featType $FME_FeaturesRead($featType)]的# count;把美元outputFile”- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -“把美元outputFile”“把美元outputFile”- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -“把美元outputFile“功能写总结”把美元outputFile”- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -“#循环排序列出的功能类型,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,并将它们的计数输出到# the summary文件中。同时,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_MF_DIR_UNIX) / recordTranslationODBC.tcl FME_END_TCL来源
# ========================================================================= # # recordTranslationODBC.tcl # # This script records the execution of a translation using # the TclODBC package.这个示例包括创建用于存储翻译结果的# Access数据库和表。每个转换运行插入到表中的一行。注意,对于穴位生产系统,“put”语句将被删除。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.如果#数据库是基于服务器的,我们不会这样做,但在本例中,我们只使用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,首先,如果DSN已经存在,总是删除它。如果我们使用ODBC连接到一个“真正的”数据库,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),开始时间的时间戳,EndTime时间戳,CpuTime翻倍,成功的CHAR(3),NumFeatures INTEGER)" } else { puts "XLATION_RESULTS table present in database $dbfile" } # ========================================================================= # All of that was just setup,现在我们可以插入行,#提交,如果{$FME_Status == 0} {set Success no} db "INSERT INTO XLATION_RESULTS (MappingFileID,开始时间,EndTime,CpuTime,成功,NumFeatures)值(“FME_MappingFileId美元”,\ { ts的FME_StartingTimeStamp美元\ },\ { ts的FME_EndingTimeStamp美元\ },FME_CPUTime美元,“美元成功”,FME_TotalFeaturesWritten美元)“db数据库断开# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = #如果你是连接到服务器的数据库,您可能不会在最后删除ODBC DSN。但由于我们是基于文件的#我们将删除它数据库配置remove_dsn $驱动程序"DSN=$ DSN "
本例使用外部脚本使用Oratcl包将翻译活动的记录插入Oracle数据库。
Oratcl
要在FME环境中使用Oratcl,遵循以下步骤:
$ (FME_MF_DIR_UNIX) / recordTranslationOracle.tcl FME_END_TCL来源
# ========================================================================= # # recordTranslationOracle.tcl # # This script records the execution of a translation using # the Oratcl package.这个示例包括创建用于存储转换结果的# XLATION_RESULTS表。每个转换运行插入到表中的一行。package require Oratcl # ========================================================================= # Login to the Oracle service set username scott set password tiger set service amidala set loginHandle [oralogon $username/$password@$service] # ========================================================================= # Determine if the xlation_results table we wish to record results to exists set tableExists no set statementHandle [oraopen $loginHandle] orasql $statementHandle "select * from user_tables where table_name = 'XLATION_RESULTS'" while {[orafetch $statementHandle -datavariable row] == 0} { set tableExists yes } # ========================================================================= # Create the xlation_results table if we need to if {$tableExists == "no"} { orasql $statementHandle "CREATE TABLE XLATION_RESULTS ( MappingFileID VARCHAR(50),开始时间的时间戳,EndTime时间戳,CpuTime浮动,XlationSuccessful CHAR (3),NumFeatures INTEGER)" } # ========================================================================= # Insert the translation results into the table set Success yes if {$FME_Status == 0} {set Success no} orasql $statementHandle "INSERT INTO XLATION_RESULTS (MappingFileID,开始时间,EndTime,CpuTime,XlationSuccessful,NumFeatures)值(“FME_MappingFileId美元”,时间戳FME_StartingTimeStamp美元,时间戳FME_EndingTimeStamp美元,FME_CPUTime美元,“美元成功”,$FME_TotalFeaturesWritten)" -commit # ========================================================================= # Shut down the statement handle oraclose $statementHandle # ========================================================================= # Logout of our oracle service oralogoff $loginHandle
©2019安全亚搏在线软件公司|法律