本文转自:http://www.cnblogs.com/afarmer/archive/2012/11/05/2755327.html

PowerDesigner多用来进行数据库模型设计,具有SQL语句自动生成等功能。当然,也有不少缺点,比如团队分享。

一、设置PowerDesigner模型视图中数据表显示列

1、Tools-Display Preference…

2、窗口左边Category中General Settings下选择Table

3、窗口右边Advanced…

4、窗口左边选择Columns

5、窗口右边List columns中,选择要显示的列

二、设置PowerDesigner设计表时,自动将name列值中的一部分复制到code列

1、把name/code自动复制功能打开。默认是打开的。

Tool-Genneral-Options Dialog-Name to Code mirroring

2、Tools->Model Options....->Naming Convention 
3、选中Name,并勾选Enable name/code conversions. 
4、选择Name To Code

粘贴脚本代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
脚本1:
.set_value(_First, true, new)
.foreach_part(%Name%, "'#'")
.if (%_First%)
.delete(%CurrentPart%)
.enddelete
.set_value(_First, false, update)
.else
%CurrentPart%
.endif
.next
这个例子是把Name内容的#号后边的内容当作Code.
  
脚本2:
.set_value(_First, true, new)
.foreach_part(%Name%, "'#'")
.if (%_First%)
%CurrentPart%
.set_value(_First, false, update)
.endif
.next
 这个例子是把Name内容的#号前边的内容当作Code.

三、从数据库导入数据到PowerDesigner中后,将comment列值复制到name列

运行脚本 Tools->Execute Commands->Edit/Run Scripts(Ctrl Shift X)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
'******************************************************************************
'* File:     comment2name.vbs
'* Purpose:  在PowerDesigner的PDM图形窗口中显示数据列的中文注释
'* Title:    将字段的comment赋值到字段的name中
'* Category: 打开物理模型,运行本脚本(Ctrl+Shift+X)
'* Copyright:foxzz@163.com,2006/07/25 .
'* Author:   foxzz
'* Created: 
'* Modified:
'* Version:  1.0
'* Comment:  遍历物理模型中的所有表,将字段的comment赋值到字段的name中。
'            在将name置换为comment过程中,需要考虑的问题
'            1、name必须唯一,而comment有可能不唯一。
'               处理办法是如果字段的comment重复,则字段的name=comment+1、2、3...
'            2、comment值有可能为空,这种情况下对字段的name不处理。
'               针对oracle数据库,将comment on column 字段名称 is '';添加到C:/pdcomment.txt文件中。
'               在补充comment完毕后,便于在数据库中执行       
'******************************************************************************
 
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
 
Dim system, file
Set system = CreateObject("Scripting.FileSystemObject")
Dim ForReading, ForWriting, ForAppending   '打开文件选项
ForReading   = 1 ' 只读
ForWriting   = 2 ' 可写
ForAppending = 8 ' 可写并追加
'打开文本文件
Set file = system.OpenTextFile("C:/pdcomment.txt", ForWriting, true)
 
 
'判断当前model是否物理数据模型
Dim mdl
Set mdl = ActiveModel
If (mdl Is Nothing) Then
   MsgBox "处理对象无模型"
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
   MsgBox "当前模型不是物理数据模型"
Else
   ProcessFolder mdl,file
End If
file.Close
 
 
'******************************************************************************
Private sub ProcessFolder(folder,file)
 
Dim i,j,k
i=0:j=0:k=0
 
'列数组,记录字段里不重复的comment
Dim ColumnComment()
Dim ColumnCommentNumber()
ReDim Preserve ColumnComment(i)
ReDim Preserve ColumnCommentNumber(i)
 
Dim tbl   '当前表
Dim col   '当前字段
dim curComment  '当前字段comment
 
'处理模型中的表
for each tbl in folder.tables
    if not tbl.isShortcut then
       if len(trim(tbl.comment))<>0 then
          '可以在这里显示table的comment
          'tbl.name = tbl.name+"("+trim(tbl.comment)+")"
       end if 
 
       '处理表中的列
       for each col in tbl.columns
           k = 0
           curComment = trim(col.comment)
           if len(curComment)<>0 then
              '遍历相异的comment数组
              for j = 0 to i
                  if ColumnComment(j) = curComment then
                     '如果找到相同的comment,则相关计数器加1
                     ColumnCommentNumber(j) = ColumnCommentNumber(j) + 1
                     k = j
                  end if
              Next
              '如果没有相同的comment,则k=0,此时ColumnCommentNumber(0)也为0
              '否则ColumnCommentNumber(k)不为0
              if ColumnCommentNumber(k) <> 0 then
                 col.name = curComment & cstr(ColumnCommentNumber(k))
              else
                 col.name  = curComment
                 'ColumnComment(0)、ColumnCommentNumber(0)永远为空
                 '将相异的comment记录添加到数组中
                 i = i + 1
                 ReDim Preserve ColumnComment(i)
                 ReDim Preserve ColumnCommentNumber(i)
                 ColumnComment(i) = curComment
                 ColumnCommentNumber(i) = 0
              end if
           else
              '写入文件中
              file.WriteLine "comment on column "+ tbl.name+"."+col.code+" is '';"          
           end if
       next
    end if
    '由于不同表的name允许相同,因此此时重新初始化。
    '因为ColumnComment(0)、ColumnCommentNumber(0)为空,可以保留
    ReDim Preserve ColumnComment(0)
    ReDim Preserve ColumnCommentNumber(0)
    i=0:j=0:k=0
 
next
 
Dim view  '当前视图
for each view in folder.Views
    if not view.isShortcut then
       '可以在这里显示view的comment
       'view.name =  view.comment
    end if
next
 
'对子目录进行递归
Dim subpackage 'folder
For Each subpackage In folder.Packages
    if not subpackage.IsShortcut then
       ProcessFolder subpackage , file
    end if
Next
 
end sub

四、将name列值复制到comment列

运行脚本 Tools->Execute Commands->Edit/Run Scripts(Ctrl Shift X)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'把pd中那么name想自动添加到comment里面
'如果comment为空,则填入name;如果不为空,则保留不变,这样可以避免已有的注释丢失.
 
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 comment 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 trim(tab.comment)="" then '如果有表的注释,则不改变它.如果没有表注释.则把name添加到注释里面.
       tab.comment = tab.name
    end if 
 Dim col ' running column 
 for each col in tab.columns
  if trim(col.comment)="" then '如果col的comment为空,则填入name,如果已有注释,则不添加;这样可以避免已有注释丢失.
   col.comment= col.name
  end if
 next 
  end if 
 next 
   
 Dim view 'running view 
 for each view in folder.Views 
  if not view.isShortcut and trim(view.comment)=""  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

参考:

1、PowerDesigner中Table视图同时显示Code和Namehttp://blog.csdn.net/downmoon/article/details/8108968

2、PowerDesigner Name/Code自动调整(转)http://hi.baidu.com/jonik/item/7d39588c3dda708e4514cf76

3、在PowerDesigner的PDM图形窗口中显示数据列的中文注释http://blog.csdn.net/zengzhe/article/details/974205

4、powerDesigner 把name项添加到注释(comment),完美方案!http://www.cnblogs.com/dukey/archive/2010/01/20/dukey.html

【转】PowerDesigner使用方法小结的更多相关文章

  1. PowerDesigner实用方法小结(1)

    PowerDesigner使用方法小结 PowerDesigner多用来进行数据库模型设计,具有SQL语句自动生成等功能.当然,也有不少缺点,比如团队分享. 一.设置PowerDesigner模型视图 ...

  2. PowerDesigner使用方法小结

    PowerDesigner多用来进行数据库模型设计,具有SQL语句自动生成等功能.当然,也有不少缺点,比如团队分享. 一.设置PowerDesigner模型视图中数据表显示列 1.Tools-Disp ...

  3. PowerDesigner实用技巧小结(3)

    PowerDesigner实用技巧小结(3) PowerDesigner 技巧小结 sqlserver数据库databasevbscriptsqldomain 1.PowerDesigner 使用 M ...

  4. PowerDesigner实用技巧小结(2)

    PowerDesigner实用技巧小结 1.ORACLE数据库建模时,由于ORACLE的表名.字段名如果是小写会有一定的麻烦,需要将小写转化为大写? (1)在打开pdm的情况下,进入Tools-Mod ...

  5. 在Linux下禁用IPv6的方法小结

    在Linux下禁用IPv6的方法小结--http://www.jb51.net/LINUXjishu/335724.html 这篇文章主要介绍了在Linux下禁用IPv6的方法小结,禁用IPv6的操作 ...

  6. 【转】TextView长按复制实现方法小结

    有这么一个需求,用户在浏览文本信息时希望长按信息就能弹出复制的选项方便保存或者在别的页面使用这些信息.类似的, 就像长按WebView或者EditText的内容就自动弹出复制选项. 这里面主要是2个特 ...

  7. static使用方法小结

    static使用方法小结 statickeyword是C, C++中都存在的keyword, 它主要有三种使用方式, 当中前两种仅仅指在C语言中使用, 第三种在C++中使用(C,C++中详细细微操作不 ...

  8. T-SQL切割字符串方法小结

    T-SQL切割字符串方法小结,只有表值函数那个是自己的思想,其它都是来源于网络的思想,请大家不要笑话,嘻嘻~网上大牛太多,这点东西虽然上不了台面,但是也算是自己的一个学习吧,能够对一个人有用也行.再不 ...

  9. asp.net检查验证字符串是否为纯数字方法小结

    原文  asp.net检查验证字符串是否为纯数字方法小结 在asp.net中验证字符串是不是为数字我们没有像php中那么多丰富的函数来直接使用,这里我整理了一些比较实例的验证字符串是否为纯数字方法代码 ...

随机推荐

  1. 虚拟机 vlan trunk 特性

    1. 功能 1)允许不同vlan的network下的虚拟机之间通信.一般情况下,虚拟机只能在相同vlan的网络下通信. 2)允许虚拟机发送vlan报文. 2. 组网图 虚拟机出来的tap设备连接到tb ...

  2. xml_MathML的基本知识点__这东西要自己实践最好

    1 : <mi> 一般的字符串 2: <mo> 操作字符串 <mo> ( </mo> <mo>∑</mo> 3:<mn&g ...

  3. 【poj2342】 Anniversary party

    http://poj.org/problem?id=2342 (题目链接) 题意 没有上司的舞会... Solution 树形dp入门题. dp[i][1]表示第i个节点的子树当节点i去时的最大值,d ...

  4. asp.net 实现在线打印功能,jQuery打印插件PrintArea实现自动分页

    使用的组件:jQuery打印插件PrintArea,有兴趣的可以研究一下. 使用方法略过,这里将介绍如何实现打印多页是可以分页. 现在提供两种方法思路: 1.根据特定的打印机型号和使用的纸张类型,然后 ...

  5. jQuery根据下拉列表的选择进行不同的操作

    需求:选择了某个下拉列表选项,进行不同的操作 代码部分: <!doctype html> <html> <head> <meta charset=" ...

  6. JAVA中的数组是对象吗?

    public class Main{ public static void main(String[] args) { int a[]={1,9}; //Object obj=new int[10]; ...

  7. Swift开发学习-01 Swift介绍

    本教程是笔者在自学IOS/Swift知识的总结,适用于通过对Objictive C编程的运用并需要了解基于iOS程序的iPhone和iPad的程序员.做一个有bigger的’攻城狮‘,有尊严的工作,快 ...

  8. Spring学习2—Spring容器

    一.Spring容器接口关系 容器是Spring框架的核心,Spring容器就是一个巨大的工厂.Spring容器使用Ioc(控制反转(Inversion of Control )管理所有组成应用系统的 ...

  9. Jquery+Ajax+Json的使用(微信答题实例)

    —————————————————————TP框架下的方法————————————————————————

  10. yii 10.16

    什么是框架? a)         框架就是一个半成品,一个帮助我们完成业务流程的程序 b)        框架融合了很多的功能,但是不会给我们具体功能模块 c)         我们需要在框架的基础 ...