PowerDesigner批量增加字段
1.编写脚本
Option Explicit ValidationMode = True InteractiveMode = im_Batch Dim mdl ' the current model Dim col_to_add '要新增的字段对象 Dim col_to_add_code '要新增的字段编码 Dim col_to_add_name '要新增的字段变量名 Dim col_to_add_datatype '要新增的字段类型 Dim col_to_add_comment '要新增的字段注释 '设置新增字段的属性 col_to_add_code = "tenant_id" col_to_add_name = "商户id" col_to_add_datatype = "int" col_to_add_comment = "商户id" ' 获取当前获取焦点的模型 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 ' 批量增加字段具体实现 Private Sub ProcessFolder(folder) 'On Error Resume Next Dim Tab 'running table '测试 For Each Tab In folder.tables If Not tab.isShortcut Then '测试 'and Tab.name = "参数配置表" 测试时限定表 MsgBox(Tab.name) Dim col,has_col has_col = 0 For Each col In tab.columns If InStr(col.code,col_to_add_code) > 0 Then has_col = 1 Exit For End If Next 'MsgBox(has_col) If has_col <> 1 Then Set col_to_add = Tab.Columns.CreateNew col_to_add.name = col_to_add_name col_to_add.code = col_to_add_code col_to_add.DataType = col_to_add_datatype col_to_add.comment = col_to_add_comment End If End If Next ' 遍历文件夹下的包 Dim f ' running folder For Each f In folder.Packages If Not f.IsShortcut Then ProcessFolder f End If Next End Sub
2. 运行脚本
调出执行命令窗口
1. 进入Powerdesigner后,按 CTRL+SHIFT+X 调出窗口。
2. 打开选项卡,tools > execute commands。
输入命令,修改开头字段的注释那部分,运行即可。
3. 脚本参考
帮助文件Customizing and Extending PowerDesigner > Scripting PowerDesigner > Running Scripts in PowerDesigner