注:本例中的格式,VBS格式固定(不像JAVA样不叫自由),如if……then+回车+语句+回车+end if
http://www.cnblogs.com/liubiqu/archive/2008/04/24/1170108.html
在设计的时候经常会碰到注释和Name不统一,需要手工复制的问题。其实PD提供了很好的方法可以批量进行调整。
我写了一个递归的修改方法,如下所示:可做为参考。
[2008年5月1日]如果需要对name 进行赋值的时候可能会出现同名的错误,所以可以利用 VBS中的 On Error Resume Next这个语句进行跳过。如
我写了一个递归的修改方法,如下所示:可做为参考。
1
'
******************************************************************************
2 ' * File: CommentVsName.vbs
3 ' * Purpose: 把字段及表注释为空的用name来代替
4 ' * Title: 保证每个字段及表都有注释
5 ' * Category: 注释
6 ' * Author: lbq(buddy) liubiqu@sina.com
7 ' * Created: 2008年3月24日
8 ' * Modified: 2008年4月24日
9 ' * Use: 打开PDM,运行本脚本(Ctrl+Shift+X)
10 ' * Version: 1.0
11 ' * Comment: 遍历PDM中的所有包,把数据表及字段的注释为空的部分用Name来替换
12 ' * Copyright (C) 2008 topsthink Inc.
13 ' ******************************************************************************
14
15 Option Explicit
16 ValidationMode = True
17 InteractiveMode = im_Abort
18
19
20 Dim mdl ' 定义当前的模型
21
22 ' 通过全局参数获得当前的模型
23 Set mdl = ActiveModel
24 If (mdl Is Nothing ) Then
25 MsgBox " 没有选择模型,请选择一个模型并打开. "
26 ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
27 MsgBox " 当前选择的不是一个物理模型(PDM). "
28 Else
29 ProcessFolder mdl
30 End If
31
32
33 ' --------------------------------------------------------------------------------
34 ' 功能函数
35 ' --------------------------------------------------------------------------------
36 Private Sub ProcessFolder(folder)
37 Dim Tab ' 定义数据表对象
38 for each Tab in folder.tables
39 if not tab.isShortcut then
40 if tab.comment = "" then tab.comment = tab.name ' 进行判断并赋值
41 Dim col ' 定义列对象
42 for each col in tab.columns
43 if col.comment = "" then col.comment = col.name ' 进行判断并赋值
44 next
45 end if
46 next
47
48 ' 对子包进行递归,如果不使用递归只能取到第一个模型图内的表
49 dim subfolder
50 for each subfolder in folder.Packages
51 ProcessFolder subfolder
52 next
53
54 ' msgbox "完成把comment为空的内容用name代替"
55 End Sub
2 ' * File: CommentVsName.vbs
3 ' * Purpose: 把字段及表注释为空的用name来代替
4 ' * Title: 保证每个字段及表都有注释
5 ' * Category: 注释
6 ' * Author: lbq(buddy) liubiqu@sina.com
7 ' * Created: 2008年3月24日
8 ' * Modified: 2008年4月24日
9 ' * Use: 打开PDM,运行本脚本(Ctrl+Shift+X)
10 ' * Version: 1.0
11 ' * Comment: 遍历PDM中的所有包,把数据表及字段的注释为空的部分用Name来替换
12 ' * Copyright (C) 2008 topsthink Inc.
13 ' ******************************************************************************
14
15 Option Explicit
16 ValidationMode = True
17 InteractiveMode = im_Abort
18
19
20 Dim mdl ' 定义当前的模型
21
22 ' 通过全局参数获得当前的模型
23 Set mdl = ActiveModel
24 If (mdl Is Nothing ) Then
25 MsgBox " 没有选择模型,请选择一个模型并打开. "
26 ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
27 MsgBox " 当前选择的不是一个物理模型(PDM). "
28 Else
29 ProcessFolder mdl
30 End If
31
32
33 ' --------------------------------------------------------------------------------
34 ' 功能函数
35 ' --------------------------------------------------------------------------------
36 Private Sub ProcessFolder(folder)
37 Dim Tab ' 定义数据表对象
38 for each Tab in folder.tables
39 if not tab.isShortcut then
40 if tab.comment = "" then tab.comment = tab.name ' 进行判断并赋值
41 Dim col ' 定义列对象
42 for each col in tab.columns
43 if col.comment = "" then col.comment = col.name ' 进行判断并赋值
44 next
45 end if
46 next
47
48 ' 对子包进行递归,如果不使用递归只能取到第一个模型图内的表
49 dim subfolder
50 for each subfolder in folder.Packages
51 ProcessFolder subfolder
52 next
53
54 ' msgbox "完成把comment为空的内容用name代替"
55 End Sub
[2008年5月1日]如果需要对name 进行赋值的时候可能会出现同名的错误,所以可以利用 VBS中的 On Error Resume Next这个语句进行跳过。如
1
Private
Sub
ProcessFolder(folder)
2
Dim
Tab
'
定义数据表对象
3
for
each
Tab in folder.tables
4
if
not
tab.isShortcut
then
5
if
tab.comment
<>
""
then
tab.name
=
tab.comment
&
"
(
"
&
tab.name
&
"
)
"
'
进行判断并赋值
6
Dim
col
'
定义列对象
7
for
each
col in tab.columns
8
if
col.comment
<>
""
then
9
On
Error
Resume
Next
'
增加此句
10
col.name
=
col.comment
'
进行判断并赋值
11
end
if
12
next
13
end
if
14
next
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
2
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
3
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
4
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
5
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
6
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
7
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
8
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
9
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
10
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
11
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
12
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
13
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
14
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
---------------------回复----------------------- 大家可以参考PD里面有一个C:\Program Files\Sybase\PowerDesigner 9\VB Scripts目录下的脚本,这些都是一个实习的实例,不过要了解每个模型的对象及属性还是要去看一下PD的帮助(直接在写脚本的时候点help就可以看到了)。