在用PowerDesigner时,常常在NAME或Comment中写中文在Code中写英文,Name只会显示给我们看,Code会使用在代码中,但Comment中的文字会保存到数据库TABLE的Description中,有时候我们写好了Name再写一次Comment很麻烦,以下两段代码就可以解决这个问题。
在PowerDesigner中PowerDesigner->Tools->Execute Commands->Edit/Run Scripts(Ctrl Shift X),然后将下面的脚本粘贴进去,并运行,即可
1代码一:将Name中的字符COPY至Comment中 2'****************************************************************************** 3'* File: name2comment.vbs 4'* Purpose: Database generation cannot use object names anymore 5' in version 7 and above. 6' It always uses the object codes. 7' 8' In case the object codes are not aligned with your 9' object names in your model, this script will copy 10' the object Name onto the object Comment for 11' the Tables and Columns. 12' 13'* Title: 14'* Version: 1.0 15'* Company: Sybase Inc. 16'****************************************************************************** 17Option Explicit 18ValidationMode = True 19InteractiveMode = im_Batch 20 21Dim mdl ' the current model 22 23' get the current active model 24Set mdl = ActiveModel 25If (mdl Is Nothing) Then 26 MsgBox "There is no current Model " 27ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then 28 MsgBox "The current model is not an Physical Data model. " 29Else 30 ProcessFolder mdl 31End If 32 33' This routine copy name into comment for each table, each column and each view 34' of the current folder 35Private sub ProcessFolder(folder) 36 Dim Tab 'running table 37 for each Tab in folder.tables 38 if not tab.isShortcut then 39 tab.comment = tab.name 40 Dim col ' running column 41 for each col in tab.columns 42 col.comment= col.name 43 next 44 end if 45 next 46 47 Dim view 'running view 48 for each view in folder.Views 49 if not view.isShortcut then 50 view.comment = view.name 51 end if 52 next 53 54 ' go into the sub-packages 55 Dim f ' running folder 56 For Each f In folder.Packages 57 if not f.IsShortcut then 58 ProcessFolder f 59 end if 60 Next 61end sub 62 63代码二:将Comment中的字符COPY至Name中 64Option Explicit 65ValidationMode = True 66InteractiveMode = im_Batch 67 68Dim mdl ' the current model 69 70' get the current active model 71Set mdl = ActiveModel 72If (mdl Is Nothing) Then 73 MsgBox "There is no current Model " 74ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then 75 MsgBox "The current model is not an Physical Data model. " 76Else 77 ProcessFolder mdl 78End If 79 80Private sub ProcessFolder(folder) 81On Error Resume Next 82 Dim Tab 'running table 83 for each Tab in folder.tables 84 if not tab.isShortcut then 85 tab.name = tab.comment 86 Dim col ' running column 87 for each col in tab.columns 88 if col.comment="" then 89 else 90 col.name= col.comment 91 end if 92 next 93 end if 94 next 95 96 Dim view 'running view 97 for each view in folder.Views 98 if not view.isShortcut then 99 view.name = view.comment 100 end if 101 next 102 103 ' go into the sub-packages 104 Dim f ' running folder 105 For Each f In folder.Packages 106 if not f.IsShortcut then 107 ProcessFolder f 108 end if 109 Next 110end sub 111 112代码三:将Name中的字符COPY至Comment中(优化) 113'把pd中那么name想自动添加到comment里面 114'如果comment为空,则填入name;如果不为空,则保留不变,这样可以避免已有的注释丢失. 115 116Option Explicit 117ValidationMode = True 118InteractiveMode = im_Batch 119 120Dim mdl ' the current model 121 122' get the current active model 123Set mdl = ActiveModel 124If (mdl Is Nothing) Then 125 MsgBox "There is no current Model " 126ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then 127 MsgBox "The current model is not an Physical Data model. " 128Else 129 ProcessFolder mdl 130End If 131 132' This routine copy name into comment for each table, each column and each view 133' of the current folder 134Private sub ProcessFolder(folder) 135 Dim Tab 'running table 136 for each Tab in folder.tables 137 if not tab.isShortcut then 138 if trim(tab.comment)="" then '如果有表的注释,则不改变它.如果没有表注释.则把name添加到注释里面. 139 tab.comment = tab.name 140 end if 141 Dim col ' running column 142 for each col in tab.columns 143 if trim(col.comment)="" then '如果col的comment为空,则填入name,如果已有注释,则不添加;这样可以避免已有注释丢失. 144 col.comment= col.name 145 end if 146 next 147 end if 148 next 149 150 Dim view 'running view 151 for each view in folder.Views 152 if not view.isShortcut and trim(view.comment)="" then 153 view.comment = view.name 154 end if 155 next 156 157 ' go into the sub-packages 158 Dim f ' running folder 159 For Each f In folder.Packages 160 if not f.IsShortcut then 161 ProcessFolder f 162 end if 163 Next 164end sub