---经验证,Sybase PowerDesigner v15.1.0成功!
--注意:需要当前激活model是Physical DM,因为是导入物理数据模型。
Option Explicit
'Dim system, file
Set system = CreateObject("Scripting.FileSystemObject") '创建文件对象
Dim ForReading, ForWriting, ForAppending
dim str
dim tittle
dim first
ForReading = 1 ' 设置文件只读
ForWriting = 2 ' 设置文件写入
ForAppending = 8 ' 设置文件追加
'-----------------------------------------------------------------------------
' 主要程序
'-----------------------------------------------------------------------------
Set file = system.OpenTextFile("E:\xfm\PowerDesigner_Training\table.txt", ForReading)'打开文本文档
Dim noLine
Dim Tab '定义一个表,vbscript中变量没有那么严格的类型,但此变量将来将用来表示table
ValidationMode = True
Dim mdl ' 定义当前激活的模型,也就是mdl
Dim Col
dim dm, dmstr
Dim SSS
Dim isNewTable
Set mdl = ActiveModel '获取当前激活模型
set Tab = mdl.Tables.CreateNew
isNewTable = True
first=file.readline '读文档按行读
tittle=split(first) '以空格分隔划分入数组,获取的是表的属性,可以获取更多属性,根据实际情况而定
tab.name=tittle(0) 'name
tab.code=tittle(1) 'code
tab.comment=tittle(2) 'comment
Do While file.AtEndOfStream <> True '循环读取文档的每一行
SSS = file.ReadLine
str=split(SSS)
if isNewTable = True then
if SSS <> "" then
isNewTable = False
end if
elseif SSS = "" then
set Tab = mdl.Tables.CreateNew '创建新表,这是读到空行时的表现,自己用来警示
else
set Col=tab.Columns.CreateNew '创建一行字段
Col.name = str(0) '依次设置属性,同表的属性,字段熟悉也可以设置更多,根据实际情况
Col.Code= str(1)
col.datatype=str(2)
col.Comment=str(3)
end if
Loop
file.Close