您的位置:首页 > 编程语言 > VB

利用VBA把PowerDesigner的comment复制到name

2015-12-18 14:13 721 查看
代码如下:

Option   Explicit
'-------------------------------------------------------------------------------
'作用:PowerDesigner物理模型复制comment到name
'
'作者: Lio5n
'
'时间: 2015-12-22
'
'版本: V2.0
'
'注意:如果name有值,将会覆盖;可以重复执行,不会多次复制
'-------------------------------------------------------------------------------
ValidationMode   = True
InteractiveMode  = im_Batch

'----------------------------------请按需设置-----------------------------------

CONST   CopyType = "ONE"            '执行模式 [ ONE-单表 ALL-所有表 ]
CONST   TabCode  = "TabCode"        '单表模式下,表的Code
CONST   ViewCode = "ViewCode"       '单表模式下,视图的Code

'-------------------------------------------------------------------------------

Dim   mdl   '当前模型
Dim   Cnt   '处理个数
Cnt = 0

Set mdl = ActiveModel
If ( mdl Is Nothing ) Then
MsgBox "未找到活动的模型!"
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
MsgBox "当前模型不是物理模型!"
Else
ProcessFolder mdl
MsgBox "执行完成,共检索 [ " + CStr(Cnt) + " ] 张表!"
End If

Private Sub ProcessFolder(folder)
On Error Resume Next

Dim Tab   '定义表
For Each Tab In folder.tables
If CopyType = "ONE" And UCase(Tab.code) <> UCase(TabCode) Then
ElseIf Not Tab.isShortcut Then
Cnt = Cnt + 1

'表处理
If Trim(Tab.comment) <> "" Then
Tab.name = Trim(Tab.comment)
End If

'字段处理
Dim Col
For Each Col In Tab.columns
If Trim(Col.comment) <> "" Then
Col.name = Trim(Col.comment)
End If
Next

End If
Next

'视图处理
Dim View
For Each View In folder.Views
If CopyType = "ONE" And UCase(View.code) <> UCase(ViewCode) Then
Else
If Not View.isShortcut Then
Cnt = Cnt + 1
If Trim(View.comment) <> "" Then
View.name = Trim(View.comment)
End If
End IF
End If
Next

'进入子floder
Dim f
For Each f In folder.Packages
If Not f.isShortcut Then
ProcessFolder f
End If
Next

End Sub
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: