Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
Dim mdl ‘当前model
‘获取当前活动model
Set mdl = ActiveModel
If (mdl Is Nothing) Then
MsgBox "There is no current Model "
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then ‘如果是处理pdm,这里换成PdPDM.cls_Model
MsgBox "The current model is not an Physical Data model. "
Else
ProcessFolder mdl
End If
Private sub ProcessFolder(folder)
dim tab
‘11111111111111111111111111111111111111111111111111111111111111111
for each tab in folder.tables
if not tab.isShortcut then
‘处理每个实体或类的Name和Code
‘先处理表名
Dim code
code = tab.code
code=ManageNameFormat code
tab.code=code
tab.name=code
‘再处理每个字段的名称
dim col
for each col in tab.columns
Dim acode
acode = col.code
acode=ManageNameFormat acode
col.code=acode
col.name=acode
col.ServerCheckExpression="" ‘清除每个字段正则表达式约束
col.ListOfValues ="" ‘清除枚举项约束
col.lowvalue="" ‘清除最大值约束
col.highvalue="" ‘最小值约束
next
end if
next
‘222222222222222222222222222222222222222222222222222222222222222222222222222
‘更改特定外键名称
for each ref in folder.references
if not ref.isShortcut then
‘根据子表和主表名称更改外键字段名称,将该外键字段名称直接改为该关系名,以子表-主表方式判断
‘根据单表也可以设置
if lcase(ref.parenttable.name)=lcase("ExVersion") or lcase(ref.parenttable.name)=lcase("Ex_Version") or _
(lcase(ref.childtable.name)=lcase("GM_Arc") and lcase(ref.parenttable.name)=lcase("Point" )) or _
(lcase(ref.childtable.name)=lcase("GM_Geodesic") and lcase(ref.parenttable.name)=lcase("Point") ) then
dim col
for each col in ref.childtable.columns ‘不用遍历寻找对应table对象,直接用ref.childtable就能操作,比以前更智能
if lcase(col.name)= lcase(ref.ForeignKeyColumnList) then
output ref.childtable.name+"."+ref.ForeignKeyColumnList+ "<--------------->"+ ref.childtable.name+"."+ref.name
col.name=ref.name
col.code=col.name
end if
next
end if
end if
next
‘////////////////////////////////////////////////////////////////////////////////////
‘递归遍历子文件夹
Dim f ‘子文件夹
For Each f In folder.Packages
if not f.IsShortcut then
ProcessFolder f
end if
Next
end sub
‘函数将输入的低驼峰字符串整理成_符分割的字符串
Function ManageNameFormat (code as string) as string
Dim i
i=2
Do While i < len(code)
If mid(code,i,1)=ucase(mid(code,i,1)) and mid(code,i-1,1)=lcase(mid(code,i-1,1)) and mid(code,i-1,1)<>"_" and mid(code,i,1)<>"_" and mid(code,i-1,1)<>"2" and mid(code,i,1)<>"2" Then ‘连续大写字母不用加_
code = left(code,i-1) + "_" + mid(code,i)
i =i+ 1
End If
i =i+ 1
Loop
ManageNameFormat=code
End Function