在使用PowerDesigner设计PDM时,一般输入NAME和CODE,因为大部分的COMMENT和NAME相同,也懒得再输入一遍.但是PD本身并没有提供映射的函数.以下是我根据name2code.vbs修改的映射函数.
基本实现思想:
1,迭代所有的表,表字段,视图
2,如果他们的COMMENT为空,则将其赋值为NAME+"。"
3,如果他们的COMMENT不为空,则在COMMENT中搜索"。",取"。"之后的字符串(假设为RC),如果没有找到"。"则RC等于COMMENT
4,新的COMMENT值为:NAME+"。"+RC
使用建议:鉴于上述的实现,NAME不要包含"。",在使用时如果第一次手工输入的COMMENT时,将COMMENT的第一个字符输入为"。"最好.否则可能会因为COMMENT中有"。"或NAME中有"。"而出现偏差.
执行方式:打开要映射的DIAGRAM,然后菜单TOOLS->Excute Commands->Edit/Ran Script...将下面的代码COPY/PASTE进去,然后点击执行即可.
代码如下:[name2comment.vbs]
'******************************************************************************
'* File: name2comment.vbs
'* Title: Name to Comment Conversion
'* Model: Physical Data Model
'* Objects: Table, Column, View
'* Author: SunYJ
'* Created: 2009-04-15
'* Mod By:
'* Modified:
'* Version: 1.0
'* Memo: Modify from name2code.vbs
'******************************************************************************
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
Dim mdl ' the current model
Dim i
dim splitNC
dim splitIdx
dim newComment
dim commentLen
' get the current active model
splitNC="。"'name and comment split string
splitIdx=0
newComment=""
commentLen=0
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 copies the name into code for each table, column and view
' of the current folder
Private sub ProcessFolder(folder)
Dim Tab 'running table
Dim rc 'return code
for each Tab in folder.tables
if not tab.isShortcut then
MergeNameComment tab'tab.Comment=tab.Name
Dim col ' running column
for each col in tab.columns
MergeNameComment col'col.Comment=col.Name
next
end if
next
Dim view 'running view
for each view in folder.Views
if not view.isShortcut then
MergeNameComment view'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
private sub MergeNameComment(obj)
if obj.Comment = "" then
obj.Comment = obj.Name & splitNC
else
splitIdx=instr(obj.Comment,splitNC)
if splitIdx >= 0 then
commentLen=len(obj.Comment)
obj.Comment=obj.Name & splitNC & right(obj.Comment,commentLen-splitIdx)
end if
end if
end sub
基本实现思想:
1,迭代所有的表,表字段,视图
2,如果他们的COMMENT为空,则将其赋值为NAME+"。"
3,如果他们的COMMENT不为空,则在COMMENT中搜索"。",取"。"之后的字符串(假设为RC),如果没有找到"。"则RC等于COMMENT
4,新的COMMENT值为:NAME+"。"+RC
使用建议:鉴于上述的实现,NAME不要包含"。",在使用时如果第一次手工输入的COMMENT时,将COMMENT的第一个字符输入为"。"最好.否则可能会因为COMMENT中有"。"或NAME中有"。"而出现偏差.
执行方式:打开要映射的DIAGRAM,然后菜单TOOLS->Excute Commands->Edit/Ran Script...将下面的代码COPY/PASTE进去,然后点击执行即可.
代码如下:[name2comment.vbs]
'******************************************************************************
'* File: name2comment.vbs
'* Title: Name to Comment Conversion
'* Model: Physical Data Model
'* Objects: Table, Column, View
'* Author: SunYJ
'* Created: 2009-04-15
'* Mod By:
'* Modified:
'* Version: 1.0
'* Memo: Modify from name2code.vbs
'******************************************************************************
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
Dim mdl ' the current model
Dim i
dim splitNC
dim splitIdx
dim newComment
dim commentLen
' get the current active model
splitNC="。"'name and comment split string
splitIdx=0
newComment=""
commentLen=0
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 copies the name into code for each table, column and view
' of the current folder
Private sub ProcessFolder(folder)
Dim Tab 'running table
Dim rc 'return code
for each Tab in folder.tables
if not tab.isShortcut then
MergeNameComment tab'tab.Comment=tab.Name
Dim col ' running column
for each col in tab.columns
MergeNameComment col'col.Comment=col.Name
next
end if
next
Dim view 'running view
for each view in folder.Views
if not view.isShortcut then
MergeNameComment view'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
private sub MergeNameComment(obj)
if obj.Comment = "" then
obj.Comment = obj.Name & splitNC
else
splitIdx=instr(obj.Comment,splitNC)
if splitIdx >= 0 then
commentLen=len(obj.Comment)
obj.Comment=obj.Name & splitNC & right(obj.Comment,commentLen-splitIdx)
end if
end if
end sub