PowerDesigner,根据name自动生成commnet的脚本

来源:互联网 发布:淘宝金酷娃警车 编辑:程序博客网 时间:2024/04/29 21:37

PowerDesigner在操作上有很多的不便性,但在库的设计及SQL代码生成上还是很强大的。

由于自己写的代码生成器能够根据comment生成相关字段注释,所以,commnet还是非常重要的。以前是通过手动一条条的从Name得到到comment中去,字段比较少倒是没什么感觉,这次项目很多表都是在一百多个字段以上,所以,有点吃力。于是,在网上找了点资料,然后自己稍微加工了下,脚本如下:

Option ExplicitValidationMode = TrueInteractiveMode = im_BatchDim mdl 'the current model'get the current active modelSet mdl = ActiveModelIf (mdl Is Nothing) ThenMsgBox "There is no current Model"ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) ThenMsgBox "The current model is not an Physical Data model."ElseProcessFolder mdlEnd If'This routine copy name into code for each table, each column and each view'of the current folderPrivate sub ProcessFolder(folder)Dim Tab 'running tablefor each Tab in folder.tablesif not tab.isShortcut thenDim col 'running columnfor each col in tab.columnsIf (col.comment="") Then '已存在的comment则不更新col.comment= col.nameend ifnextend ifnextDim view 'running viewfor each view in folder.Viewsif not view.isShortcut thenview.comment = view.nameend ifnext'go into the sub-packagesDim f 'running folderFor Each f In folder.Packagesif not f.IsShortcut thenProcessFolder fend ifNextend sub

这段代码也是从网上找的。主要是加了个如果comment的为空的情况下则从name复制,否则将不处理。

PowerDesigner里的脚本是VB写的。所以,如果对VB了解的话,还是可以编写很多东西的。

代码的使用,如下图:


在这里需要注意下,运行脚本时要先在PowerDesigner选中需要处理的PDM。