PowerDesigner中 脚本实现name与comment互相转换


powerdesigner 逆向工程时,总需要将注释转为name值。

1. name转comment:通过脚本将name赋值到comment

执行位置:Open PDM – Tools – Execute Commands – Run Script
使用情景:物理模型生成SQL、数据库表时使用。
脚本:

Option Explicit
ValidationMode = True
InteractiveMode = im_Batch

Dim mdl 'the current model   

'get the current active model   
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 copy name into code for each table, each column and each view   
'of the current folder   
Private Sub ProcessFolder(folder)
    Dim Tab 'running table   
    For Each Tab In folder.tables
        If Not tab.isShortcut Then
            tab.comment = tab.name
            Dim col 'running column   
            For Each col In tab.columns
                col.comment = col.name
            Next
        End If
    Next
    
    Dim view 'running view   
    For Each view In folder.Views
        If Not view.isShortcut Then
            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

2. comment转name:通过脚本将comment赋值到name

执行位置:Open PDM – Tools – Execute Commands – Run Script
使用情景:一般数据库表或SQL通过逆向工程生成物理模型时使用。
脚本:

Option Explicit
ValidationMode = True
InteractiveMode = im_Batch

Dim mdl 'the current model   

'get the current active model   
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 copy name into code for each table, each column and each view   
'of the current folder   
Private Sub ProcessFolder(folder)
    
    Dim Tab 'running table   
    For Each Tab In folder.tables
        If Not tab.isShortcut Then
            If Len(tab.comment) <> 0 Then
                tab.name = tab.comment
            End If
            On Error Resume Next
            Dim col 'running column   
            For Each col In tab.columns
                If Len(col.comment) <> 0 Then
                    col.name = col.comment
                End If
                On Error Resume Next
            Next
        End If
    Next
End Sub

在这里插入图片描述

转载:https://blog.csdn.net/markguo_/article/details/48289425

猜你喜欢

转载自blog.csdn.net/besto229/article/details/106146599