PowerDesigner技巧集5 —- 用vbscript讓txt文本中的內容匯入PDM模型

來源:互聯網
上載者:User

如下的指令碼實現用vbscript讓txt文本中的內容匯入PDM模型

Option ExplicitDim system, fileSet system = CreateObject("Scripting.FileSystemObject") Dim ForReading, ForWriting, ForAppendingdim strdim titledim firstForReading   = 1 ' 設定檔案唯讀 ForWriting   = 2 ' 設定檔案寫入ForAppending = 8 ' 設定檔案追加Set file = system.OpenTextFile("E:\Users\hxw\Desktop\VBScript\tab.txt", ForReading)'開啟文字文件Dim noLineDim Tab  '定義一個表,vbscript中變數沒有那麼嚴格的類型,但此變數將來將用來表示tableValidationMode = TrueDim mdl ' 定義當前啟用的模型,也就是mdlDim Coldim dm, dmstrDim SSSDim isNewTableSet mdl = ActiveModel '擷取當前啟用模型set Tab = mdl.Tables.CreateNewisNewTable = Truefirst=file.readline '讀文檔按行讀title=split(first) '以空格分隔劃分入數組,擷取的是表的屬性,可以擷取更多屬性,根據實際情況而定tab.name=title(0) 'nametab.code=title(1) 'codetab.comment=title(2) 'commentDo While file.AtEndOfStream <> True '迴圈讀取文檔的每一行   SSS = file.ReadLine   str=split(SSS)   If SSS <> "" Then isNewTable = False   Else    isNewTable = True   End If   If isNewTable = True Thenfirst=file.readline '讀文檔按行讀  title=split(first)set Tab = mdl.Tables.CreateNew  '建立新表,這是讀到空行時的表現,自己用來警示tab.name=title(0) 'nametab.code=title(1) 'codetab.comment=title(2) 'commentElseset Col = tab.Columns.CreateNew '建立一列欄位Col.name = str(0) '依次設定屬性,同表的屬性,欄位熟悉也可以設定更多,根據實際情況Col.Code = str(0)col.datatype = str(2)col.comment = str(3)   End IfLoopfile.Close

tab.txt的內容如下:

表名1 表code1 表comments1
欄位名1 mycode1 VARCHAR2(32) 說明1
欄位名2 mycode2 VARCHAR2(256) 說明2

表名2 表code2 表comments2
欄位名1 mycode1 VARCHAR2(32) 說明1
欄位名2 mycode2 VARCHAR2(256) 說明2

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.