回来了,先奉献一段powerdesigner的执行脚本
帐号被封了2年,就没来看过,不过powerdesigner一直使用,
奉献一个原创代码powerdesigner脚本
大家在使用powerdesigner创建数据库表,创建类图的时候,输入了中文名称,还要翻译成英文名称或者汉字拼音,工作量繁琐单一
有段时间有空,参照了一下写了个脚本
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
' get the current active model
Dim mdl ' the current model
Set mdl = ActiveModel
If (mdl Is Nothing) Then
MsgBox "There is no Active Model"
Else
ListObjects(mdl)
End If
'-----------------------------------------
' Sub procedure to scan current package and print information on objects from current package
' and call again the same sub procedure on all children pacakge
' of the current package
'-----------------------------------------
Private Sub ListObjects(fldr) '列出所有的对象
output "Scanning " & fldr.code
Dim obj ' running object
For Each obj In fldr.children
' Calling sub procedure to print out information on the object
'DescribeObject obj
TableSetNameToCode obj
Next
' go into the sub-packages
Dim f ' running folder
For Each f In fldr.Packages '递归调用列出所有的对象
'calling sub procedure to scan children package
ListObjects f
Next
End Sub
'-----------------------------------------
' Sub procedure to print information on current object in output
'-----------------------------------------
Private Sub DescribeObject(CurrentObject)
if not CurrentObject.Iskindof(cls_NamedObject) then exit sub
output "Found "+CurrentObject.ClassName+" """+CurrentObject.Name+""", Created by "+CurrentObject.Creator+" On "+Cstr(CurrentObject.CreationDate)
End Sub
'常数 值 描述
'vbCr Chr(13) 回车符。
'vbCrLf Chr(13) & Chr(10) 回车符与换行符。
'vbFormFeed Chr(12) 换页符;在 Microsoft Windows 中不适用。
'vbLf Chr(10) 换行符。
'vbNewLine Chr(13) & Chr(10) 或 Chr(10) 平台指定的新行字符;适用于任何平台。
'vbNullChar Chr(0) 值为 0 的字符。
'vbNullString 值为 0 的字符串 与零长度字符串 ("") 不同;用于调用外部过程。
'vbTab Chr(9) 水平附签。
'vbVerticalTab Chr(11) 垂直附签;在 Microsoft Windows 中不适用。
Private Sub TableSetNameToCode(CurrentObject)
if not CurrentObject.Iskindof(cls_Table) then exit sub
'output "Found "+CurrentObject.ClassName+" """+CurrentObject.Name+""", Created by "+CurrentObject.Creator+" On "+Cstr(CurrentObject.CreationDate)
if not CurrentObject.isShortcut then
output CurrentObject.name
CurrentObject.code = "T_"&GetPy( CurrentObject.name)
CurrentObject.comment = CurrentObject.name & "_"&CurrentObject.code
Dim col ' running column
dim index1
index1 = 0
for each col in CurrentObject.columns
dim str11
str11 = GetPy( col.name)
col.code = str11 & cstr(index1 )
col.Comment = col.name & "_" & col.code
index1 = index1 + 1
next
end if
End Sub
'//生成汉字串首字母串
function GetPy(strxx)
dim i
dim getpy1
for i=1 to len(strxx)
getpy1=getpy1 & getpychar(mid(strxx,i,1))
next
output getpy1
GetPy = getpy1
End function
'//获取汉字的首字母
function getpychar(char)
'0---9 , a---z , A---Z
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
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
output getpychar + "---->" + cstr(tmpp)
End Function
这个对pdm有效,建表的时候把中文都写好,在菜单的t,ools--> execute command 下执行 run script ,贴下这段代码就可以自动给把生成表结构的代码部分按照中文拼音的首字母来转换
中间用了个自增长的编号是为了解决同名问题
[解决办法]
该回复于2009-12-01 13:00:03被版主删除
[解决办法]
该回复于2009-12-01 13:07:46被版主删除
[解决办法]
内容很好!