PowerDesigner中使用vbscript訪問對象進行大量操作

來源:互聯網
上載者:User

項目中想把PD建模的資料庫中的Name欄位全部在Comment裡也填寫一份,又不想一個表一個表的複製粘貼,所以在網上查了點偷懶省事的方法,原來可以利用VBScript指令碼控制PD中的對象進行一些大量操作。

首先是啟動你要修改的PD檔案,然後雙擊你要修改的那張圖,啟用它,注意是圖,而不是Tables下的表。然後點擊菜單“Tools->Execute Commands -> Edit/Run Script...",或者快速鍵(Ctrl+Shift+X)

然後把指令碼粘貼進去,運行就可以了。指令碼如下:

          dim   sName  
          for   each   table   in   ActiveModel.tables  
                for   each   column   in   table.columns  
                        sComm   =   column.GetExtendedAttribute("Comment")       'comment的內容  
                        sName   =   column.GetExtendedAttribute("Name")           'name的內容  
                        'if   sComm   <>   sName   then  
                            column.comment   =   column.comment + column.name  
                        'end   if  
                next  
          next

大家可以根據自己的需要隨意修改。有特殊需求的可以查它的指令碼協助文檔。

 

以下是從網上找到的一些參考資料:

Vbscript指令碼輔助Power Designer模型設計

 

 

Power Designer是資料建模中一個比較常用的工具,比較擅長大規模的E-R模型的設計。
對於一些大量操作,可以通過vbscript指令碼進行。
用法:開啟物理模型,點擊菜單“Tools->Execute Commands -> Edit/Run Script...",或者快速鍵(Ctrl+Shift+X)。
下面指令碼是一個將模型中的表名、欄位名均改成大寫的一個簡易指令碼。在Power Designer 9.5中通過運行。
vbscript,其實我不會用,所以我會選擇一個比較複雜的例子,這個例子很簡單。
至於vbscript,可以去網上看看那些函數以及結構的用法,用起來也很簡單。
關於Power Designer中用到的一些固定屬性或者實體,可以參照Power Designer的協助,可以查到。

'*****************************************************************************
'檔案:powerdesigner.ucase.VBs
'版本:1.0
'功能:遍曆物理模型中的所有表,將表名、表代碼、欄位名、欄位代碼全部由小寫改成大寫;
' 並將序列的名和代碼由小寫改成大寫。
'用法:開啟物理模型,運行本指令碼(Ctrl+Shift+X)
'備忘:
'*****************************************************************************
dim model 'current model
set model = ActiveModel

If (model Is Nothing) Then
MsgBox "There is no current Model"
ElseIf Not model.IsKindOf(PdPDM.cls_Model) Then
MsgBox "The current model is not an Physical Data model."
Else
ProcessTables model
ProcessSequences model
End If

'*****************************************************************************
'函數:ProcessSequences
'功能:遞迴遍曆所有的序列
'*****************************************************************************
sub ProcessSequences(folder)
'處理模型中的序列:小寫改大寫
dim sequence
for each sequence in folder.sequences
sequence.name = UCase(sequence.name)
sequence.code = UCase(sequence.code)
next
end sub

'*****************************************************************************
'函數:ProcessTables
'功能:遞迴遍曆所有的表
'*****************************************************************************
sub ProcessTables(folder)
'處理模型中的表
dim table
for each table in folder.tables
if not table.IsShortCut then
ProcessTable table
end if
next
'對子目錄進行遞迴
dim subFolder
for each subFolder in folder.Packages
ProcessTables subFolder
next
end sub

'*****************************************************************************
'函數:ProcessTable
'功能:遍曆指定table的所有欄位,將欄位名由小寫改成大寫,
' 欄位代碼由小寫改成大寫
' 表名由小寫改成大寫
'*****************************************************************************
sub ProcessTable(table)
dim col
for each col in table.Columns
'將欄位名由小寫改成大寫
col.code = UCase(col.code)
col.name = UCase(col.name)
next
table.name = UCase(table.name)
table.code = UCase(table.code)
end sub

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.