powerdesigner从sql脚本生成pdm文件

1、File-->Reverse Engineer(逆向工程)-->Database

2、选择数据库类型,我的是MySQL所以选择MySQL5.0

3、选择脚本文件

脚本内容:

 

查看代码
DROP TABLE IF EXISTS `drawing_library`;
CREATE TABLE `drawing_library`  (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '图纸库id',
  `file_id` bigint NULL DEFAULT NULL COMMENT '文件id',
  `project_id` bigint NOT NULL COMMENT '项目id',
  `engineering_code` varchar(60)  NULL DEFAULT NULL COMMENT '工程编码',
  `engineering_name` varchar(255)  NULL DEFAULT NULL COMMENT '工程名称',
  `file_org_level` bigint NULL DEFAULT NULL COMMENT '文件层级',
  `drawing_code` varchar(255)  NOT NULL COMMENT '图纸编码',
  `version` varchar(10)  NOT NULL COMMENT '版本',
  `file_status` int NULL DEFAULT NULL COMMENT '状态',
  `drawing_name` varchar(255)  NOT NULL COMMENT '图纸名称',
  `delivery_channel` bigint NULL DEFAULT NULL COMMENT '接收渠道',
  `receive_time` datetime NULL DEFAULT NULL COMMENT '接收时间',
  `page_count` int NULL DEFAULT NULL COMMENT '页数',
  `page_format` varchar(10)  NULL DEFAULT NULL COMMENT '图幅',
  `dispatch_code` varchar(255)  NULL DEFAULT NULL COMMENT '发文编号',
  `dispatch_time` datetime NULL DEFAULT NULL COMMENT '发文日期',
  `edit_unit` varchar(255)  NULL DEFAULT NULL COMMENT '编制单位',
  `record_person_id` varchar(40)  NULL DEFAULT NULL COMMENT '登记人',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `update_user_id` varchar(40)  NULL DEFAULT NULL COMMENT '修改人id',
  `update_time` datetime NULL DEFAULT NULL COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE
) COMMENT = '图纸库' ;

 

确定生成pdm:

4、将备注挪到powerdesigner的name

上面的步骤其实已经生成了pdm文件,但是name部分都是英文,不直观,我们把comment挪至name,便于观看,这时需要执行一个vbs脚本,如下:

1) Tools-->Execute Commands-->Edit/Run Script...

 

2) 在弹出框输入如下脚本,然后单击run

 

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    
  
Private   sub   ProcessFolder(folder)    
On Error Resume Next   
      Dim   Tab   'running     table    
      for   each   Tab   in   folder.tables    
            if   not   tab.isShortcut   then    
                  tab.name   =   tab.comment   
                  Dim   col   '   running   column    
                  for   each   col   in   tab.columns    
                  if col.comment="" then   
                  else  
                        col.name=   col.comment    
                  end if  
                  next    
            end   if    
      next    
  
      Dim   view   'running   view    
      for   each   view   in   folder.Views    
            if   not   view.isShortcut   then    
                  view.name   =   view.comment    
            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

效果:

 

另外,附一个name转到comment的脚本:

'把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

 

posted @ 2024-08-20 10:45  jiafeng  阅读(402)  评论(0编辑  收藏  举报