PowerDesigner 批量操作 comment=name code=name简拼 删除字段 批量添加字段

comment=name

复制代码
Option   Explicit 
ValidationMode   =   True 
InteractiveMode   =   im_Batch

Dim   mdl   '   the   current   model

'   get   the   current   active   model 
Set   mdl   =   ActiveModel 
If   (mdl   Is   Nothing)   Then 
  MsgBox   "There   is   no   current   Model " 
ElseIf   Not   mdl.IsKindOf(PdPDM.cls_Model)   Then 
  MsgBox   "The   current   model   is   not   an   Physical   Data   model. " 
Else 
  ProcessFolder   mdl 
End   If

Private   sub   ProcessFolder(folder) 
On Error Resume Next
  Dim   Tab   'running table 
  for   each   Tab   in   folder.tables 
if   not   tab.isShortcut   then 
  tab.comment   =   tab.name
  Dim   col   '   running   column 
  for   each   col   in   tab.columns 
  if col.name="" then
  else
col.comment=   col.name 
  end if
  next 
end   if 
  next

  Dim   view   'running   view 
  for   each   view   in   folder.Views 
if   not   view.isShortcut   then 
  view.comment   =   view.name 
end   if 
  next

  '   go   into   the   sub-packages 
  Dim   f   '   running   folder 
  For   Each   f   In   folder.Packages 
if   not   f.IsShortcut   then 
  ProcessFolder   f 
end   if 
  Next 
end   sub
复制代码

 

 comment=name+code=name简拼

 

复制代码
Option   Explicit 
ValidationMode   =   True 
InteractiveMode   =   im_Batch

Dim   mdl   '   the   current   model

'   get   the   current   active   model 
Set   mdl   =   ActiveModel 
If   (mdl   Is   Nothing)   Then 
  MsgBox   "There   is   no   current   Model " 
ElseIf   Not   mdl.IsKindOf(PdPDM.cls_Model)   Then 
  MsgBox   "The   current   model   is   not   an   Physical   Data   model. " 
Else 
  ProcessFolder   mdl 
End   If

Private   sub   ProcessFolder(folder) 
On Error Resume Next
  Dim   Tab   'running table 
  for   each   Tab   in   folder.tables 
if   not   tab.isShortcut   then 
  tab.comment   =   tab.name
  Dim   col   '   running   column 
  for   each   col   in   tab.columns 
  if col.name="" then
  else
col.comment=   col.name 
col.code=  GetPy( col.name )
  end if
  next 
end   if 
  next

  Dim   view   'running   view 
  for   each   view   in   folder.Views 
if   not   view.isShortcut   then 
  view.comment   =   view.name 
end   if 
  next

  '   go   into   the   sub-packages 
  Dim   f   '   running   folder 
  For   Each   f   In   folder.Packages 
if   not   f.IsShortcut   then 
  ProcessFolder   f 
end   if 
  Next 
end   sub


' 生成中文串首字母串  
function GetPy(strxx)  
    dim i  
    dim getpy1  
    for i=1 to len(strxx)  
        getpy1=getpy1 & getpychar(mid(strxx,i,1))  
        next  
        GetPy = getpy1  
End function  
  
' 获取中文单字的首字母  
Function getpychar(char)  
    'Asc 函数返回与字符串的第一个字母对应的ANSI 字符代码  
    ' 数字、字母和下划线不予转换,直接返回  
    if ((asc(char) >= asc("0") and asc(char) <= asc("9")) or(asc(char) >= asc("A") and asc(char) <= asc("Z")) or (asc(char) >= asc("a") and asc(char) <= asc("z")) or asc(char) = asc("_") ) then  
    ' 注意:在实际执行脚本时then 必须与if 在同一行  
        getpychar = char  
    else  
        dim tmpp:tmpp=65536+asc(char)  
        if(tmpp>=45217 and tmpp <=45252) then  
            getpychar= "A"  
        elseif(tmpp>=45253 and tmpp <=45760) then  
            getpychar= "B"  
        elseif(tmpp>=45761 and tmpp <=46317) then  
            getpychar= "C"  
        elseif(tmpp>=46318 and tmpp <=46825) then  
            getpychar= "D"  
        elseif(tmpp>=46826 and tmpp <=47009) then  
            getpychar= "E"  
        elseif(tmpp>=47010 and tmpp <=47296) then  
            getpychar= "F"  
        elseif(tmpp>=47297 and tmpp <=47613) then  
            getpychar= "G"  
        elseif(tmpp>=47614 and tmpp <=48118) then  
            getpychar= "H"  
        elseif(tmpp>=48119 and tmpp <=49061) then  
            getpychar= "J"  
        elseif(tmpp>=49062 and tmpp <=49323) then  
            getpychar= "K"  
        elseif(tmpp>=49324 and tmpp <=49895) then  
            getpychar= "L"  
        elseif(tmpp>=49896 and tmpp <=50370) then  
            getpychar= "M"  
        elseif(tmpp>=50371 and tmpp <=50613) then  
            getpychar= "N"  
        elseif(tmpp>=50614 and tmpp <=50621) then  
            getpychar= "O"  
        elseif(tmpp>=50622 and tmpp <=50905) then  
            getpychar= "P"  
        elseif(tmpp>=50906 and tmpp <=51386) then  
            getpychar= "Q"  
        elseif(tmpp>=51387 and tmpp <=51445) then  
            getpychar= "R"  
        elseif(tmpp>=51446 and tmpp <=52217) then  
            getpychar= "S"  
        elseif(tmpp>=52218 and tmpp <=52697) then  
            getpychar= "T"  
        elseif(tmpp>=52698 and tmpp <=52979) then  
            getpychar= "W"  
        elseif(tmpp>=52980 and tmpp <=53688) then  
            getpychar= "X"  
        elseif(tmpp>=53689 and tmpp <=54480) then  
            getpychar= "Y"  
        elseif(tmpp>=54481 and tmpp <=62289) then  
            getpychar= "Z"  
        else  
            getpychar=""  
        End if  
    end if  
End Function  
复制代码

 

删除字段

 

复制代码
Option   Explicit 
ValidationMode   =   True 
InteractiveMode   =   im_Batch

Dim   mdl   '   the   current   model

'   get   the   current   active   model 
Set   mdl   =   ActiveModel 
If   (mdl   Is   Nothing)   Then 
  MsgBox   "There   is   no   current   Model " 
ElseIf   Not   mdl.IsKindOf(PdPDM.cls_Model)   Then 
  MsgBox   "The   current   model   is   not   an   Physical   Data   model. " 
Else 
  ProcessFolder   mdl 
End   If

Private   sub   ProcessFolder(folder) 
On Error Resume Next
  Dim   Tab   'running table 
  for   each   Tab   in   folder.tables 
if   not   tab.isShortcut   then 
  Dim   col   '   running   column 
  for   each   col   in   tab.columns 
  if col.code="xjlx" then  '  删除的字段code
   col.Delete
end if
  next 
end   if 
  next

  Dim   view   'running   view 
  

  '   go   into   the   sub-packages 
  Dim   f   '   running   folder 
  For   Each   f   In   folder.Packages 
if   not   f.IsShortcut   then 
  ProcessFolder   f 
end   if 
  Next 
end   sub
MsgBox "success"
 
复制代码

 

批量修改表名

 

复制代码
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
 
Dim mdl 'the current model
 
'get the current active model
Set mdl = ActiveModel
If (mdl Is Nothing) Then
MsgBox "There is no current Model"
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
MsgBox "The current model is not an Physical Data model."
Else
   ProcessFolder mdl
End If
 
'This routine copy name into code for each table, each column
'of the current folder
Private sub ProcessFolder(folder)
   Dim Tab 'running table
   Dim NameStr , CodeStr
   for each Tab in folder.tables       
      '修改 Tab.name  与 Tab,code
      Tab.name  = Replace( Tab.name , "OLD_" , "NEW_")
      Tab.code  = Replace( Tab.code , "OLD_" , "NEW_")
   next
end sub
复制代码

 

 

 

 

 

批量添加字段

 

复制代码
Option Explicit
 
Dim mdl ' the current model   
Set mdl = ActiveModel
Dim Tab 'running table   
Dim col_1
Dim col_2
Dim col_3
Dim col_4
    
' 定义属性变量
for each Tab in ActiveModel.Tables

    Set col_1 = Tab.Columns.CreateNew
    Set col_2 = Tab.Columns.CreateNew
    


    col_1.name = "创建人"
    col_1.code = "CJR"
    col_1.DataType = "varchar(50)"
    col_1.comment= "创建人"

    col_2.name = "创建时间"
    col_2.code = "CJSJ"
    col_2.DataType = "datetime"
    col_2.comment= "创建时间"

    

next
MsgBox "success"

复制代码