PowerDesigner 15 name to comment mapping

在使用PowerDesigner设计PDM时,一般输入NAME和CODE,因为大部分的COMMENT和NAME相同,也懒得再输入一遍.但是PD本身并没有提供映射的函数.以下是我根据name2code.vbs修改的映射函数.
基本实现思想:
1,迭代所有的表,表字段,视图
2,如果他们的COMMENT为空,则将其赋值为NAME+"。"
3,如果他们的COMMENT不为空,则在COMMENT中搜索"。",取"。"之后的字符串(假设为RC),如果没有找到"。"则RC等于COMMENT
4,新的COMMENT值为:NAME+"。"+RC

使用建议:鉴于上述的实现,NAME不要包含"。",在使用时如果第一次手工输入的COMMENT时,将COMMENT的第一个字符输入为"。"最好.否则可能会因为COMMENT中有"。"或NAME中有"。"而出现偏差.
执行方式:打开要映射的DIAGRAM,然后菜单TOOLS->Excute Commands->Edit/Ran Script...将下面的代码COPY/PASTE进去,然后点击执行即可.

代码如下:[name2comment.vbs]
'******************************************************************************
'* File:     name2comment.vbs
'* Title:    Name to Comment Conversion
'* Model:    Physical Data Model
'* Objects: Table, Column, View
'* Author:   SunYJ
'* Created: 2009-04-15
'* Mod By:   
'* Modified: 
'* Version: 1.0
'* Memo:     Modify from name2code.vbs
'******************************************************************************

Option Explicit
ValidationMode = True
InteractiveMode = im_Batch

Dim mdl ' the current model
Dim i
dim splitNC
dim splitIdx
dim newComment
dim commentLen
' get the current active model
splitNC="。"'name and comment split string
splitIdx=0
newComment=""
commentLen=0

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 copies the name into code for each table, column and view
' of the current folder
Private sub ProcessFolder(folder)
   Dim Tab 'running table
   Dim rc 'return code

   for each Tab in folder.tables
      if not tab.isShortcut then
         MergeNameComment tab'tab.Comment=tab.Name
         Dim col ' running column
         for each col in tab.columns
            MergeNameComment col'col.Comment=col.Name
         next
      end if
   next

   Dim view 'running view
   for each view in folder.Views
      if not view.isShortcut then
         MergeNameComment view'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

private sub MergeNameComment(obj)
   if obj.Comment = "" then
      obj.Comment = obj.Name & splitNC
   else
      splitIdx=instr(obj.Comment,splitNC)
      if splitIdx >= 0 then
         commentLen=len(obj.Comment)
         obj.Comment=obj.Name & splitNC & right(obj.Comment,commentLen-splitIdx)
      end if
   end if
end sub
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值