PowerDesigner 中name与code、comment的自动变换脚本
PowerDesigner 中name与code、comment的自动转换脚本
PowerDesign?是不是感觉很古老,用惯了而已。
以下代码参考网络整理而成,经本人优化并亲测通过。
==>name转code name格式: 中文#code
.set_value(_First, true, new)
.foreach_part(%Name%, "'#'")
.if (%_First%)
.delete(%CurrentPart%)
.set_value(_First, false, update)
.else
%CurrentPart%
.endif
.foreach_part(%Name%, "'#'")
.if (%_First%)
.delete(%CurrentPart%)
.set_value(_First, false, update)
.else
%CurrentPart%
.endif
.next
在PowerDesigner中使用方法为: PowerDesigner->Tools->Model Options->NamingConvention->name 【Enable name/code Conventions】->name to code
==>name转comment name格式: 中文#code
将table name的#号之前的文字变为table的comment,将column name的#号之前的文字变为column的comment.
原来的代码是针对一个folder(CDM或PDM)下所有表(还有其他view等)进行操作,改为可以只针对特定表进行操作,如果tabname有值,则就匹配tabname值,否则如果tabname为空,则对所有表进行操作。
在PowerDesigner中使用方法为: PowerDesigner->Tools->Execute Commands->Edit/Run Scripts
-----------------------------------------------------------------------------
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
Dim tabname
Dim mdl ' the current model
'如果tabname留空,则对所有表进行操作
tabname = "应答推荐"
' 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 comment for each table, each column and each view
' of the current folder
Private sub ProcessFolder(folder)
Dim Tab 'running table
for each Tab in folder.tables
dim cando
cando = 1
if tabname<>"" and Instr(tab.name, tabname) = 0 then
cando = 0
end if
'msgBox tab.name
'msgBox cando
if not tab.isShortcut and cando=1 then
InteractiveMode = im_Batch
Dim tabname
Dim mdl ' the current model
'如果tabname留空,则对所有表进行操作
tabname = "应答推荐"
' 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 comment for each table, each column and each view
' of the current folder
Private sub ProcessFolder(folder)
Dim Tab 'running table
for each Tab in folder.tables
dim cando
cando = 1
if tabname<>"" and Instr(tab.name, tabname) = 0 then
cando = 0
end if
'msgBox tab.name
'msgBox cando
if not tab.isShortcut and cando=1 then
msgBox "即将对如下表操作:"&tab.name
tab.comment = split(tab.name ,"#")(0)
Dim col ' running column
for each col in tab.columns
col.comment= split(col.name,"#")(0)
msgBox col.comment
next
end if
next
Dim view 'running view
for each view in folder.Views
if not view.isShortcut then
view.comment = split(view.name,"#")(0)
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
for each col in tab.columns
col.comment= split(col.name,"#")(0)
msgBox col.comment
next
end if
next
Dim view 'running view
for each view in folder.Views
if not view.isShortcut then
view.comment = split(view.name,"#")(0)
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