The following script uses VBScript to import the content in the TXT text to the PDM model.
Option explicitdim system, fileset system = Createobject ("scripting. fileSystemObject ") dim forreading, forwriting, forappendingdim strdim titledim firstforreading = 1' sets File Read-Only forwriting = 2' sets file write forappending = 8' sets file append set file = system. opentextfile ("E: \ Users \ hxw \ Desktop \ VBScript \ tab.txt", forreading) 'Open the text document dim nolinedim tab 'to define a table. The variables in VBScript are not of such strict type, however, this variable will be used to indicate that tablevalidationmode = truedim MDL 'will define the currently activated model, that is, mdldim coldim DM, dmstrdim sssdim isnewtableset MDL = activemodel' to obtain the current activation model set tab = MDL. tables. createnewisnewtable = truefirst = file. readline'read document row-based read Title = Split (first) 'is divided into arrays by space. The table attributes are obtained and more attributes can be obtained, depends on the actual situation. name = title (0) 'nametab. code = title (1) 'codetab. comment = title (2) 'commentdo while file. atendofstream <> true' reads every line of the document cyclically. Sss = file. readline STR = Split (SSS) if SSS <> "" Then isnewtable = false else isnewtable = true end if isnewtable = true thenfirst = file. readline' read document read by row Title = Split (first) Set Tab = MDL. tables. createnew: Create a new table. This is the result of reading empty rows. You can use it to warn the tab. name = title (0) 'nametab. code = title (1) 'codetab. comment = title (2) 'commentelseset Col = tab. columns. createnew 'create a row of field Col. name = STR (0) 'is used to set attributes in sequence. For attributes of the same table, you can also set more attributes for fields. Col. code = STR (0) Col. datatype = STR (2) Col. comment = STR (3) end ifloopfile. close
The content of tab.txt is as follows:
Table Name 1 Table code1 table comments1
Field name 1 mycode1 varchar2 (32) description 1
Field name 2 mycode2 varchar2 (256) Description 2
Table name 2 Table code2 table comments2
Field name 1 mycode1 varchar2 (32) description 1
Field name 2 mycode2 varchar2 (256) Description 2