PowerDesigner设置脚本

添加默认字段

Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
 

Dim mdl 
Set mdl = ActiveModel
If (mdl Is Nothing) Then
   MsgBox "There is no Active Model"
Else
   ListObjects(mdl)
End If
 
 

Private Sub ListObjects(fldr) 
   output "Scanning " & fldr.code
   Dim obj 
   For Each obj In fldr.children
      
      TableSetComment obj
   Next
   		
   Dim f 
   For Each f In fldr.Packages 
     
      ListObjects f
   Next
End Sub
 
Private Sub TableSetComment(CurrentObject)
   if not CurrentObject.Iskindof(cls_Table) then exit sub
   // 添加你需要排除的表
      if instr(",standard_data_field,",","+CurrentObject.Code+",")>0 then exit sub
      if not CurrentObject.isShortcut then
        
         Dim col  
         Dim num
         //定义你需要添加的字段;
         dim create_user_id_
         dim create_time_
         dim modify_user_id_
         dim modify_time_
         dim is_delete_
         dim is_final_
         dim tenant_id_
         dim team_id_
        //给字段定义一个初始值;
        create_user_id_=1
        modify_user_id_=1
        create_time_=1
        modify_time_=1
        is_delete_=1
		is_final_ = 1
		tenant_id_ = 1
		team_id_ = 1
        //循环获取到最大列号;
         for each col in CurrentObject.columns
            
              num= num + 1
       //如果列中有此字段,赋个其他值;(可能是,实际操作如果表中有此字段,会报错)
            if col.Code="create_user_id_" then
               create_user_id_=100
            end if
            
            if col.Code="create_time_" then
               create_time_=100
              
            end if
            
            if col.Code="modify_user_id_" then
               modify_user_id_=100
             
            end if
            
            if col.Code="modify_time_" then
               modify_time_=100
 
            end if
            
            if col.Code="is_delete_" then
               is_delete_=100
 
            end if
            
            
         next
         
		//下面的操作是进行赋默认值,根据需要进行设计即可。
         if create_user_id_=1 then 
         CurrentObject.columns.CreateNewAt(num)
            for each col in CurrentObject.columns 
          
            if col.DataType="" then 
                 	col.Name="创建人"
                 	col.Code="create_user_id_"
                 	col.Comment="创建人"
                 	col.DataType="bigint(20)"
					col.Mandatory=1
            end if 
            next
            num=num+1
         end if
         
         if create_time_=1 then 
         CurrentObject.columns.CreateNewAt(num)
            for each col in CurrentObject.columns 
           
            if col.DataType="" then 
                 	col.Name="创建时间"
                 	col.Code="create_time_"
                 	col.Comment="创建时间"
                 	col.DataType="datetime"
		col.DefaultValue="CURRENT_TIMESTAMP"
            end if 
            next
            num=num+1
         end if
         

         
         if modify_user_id_=1 then 
            CurrentObject.columns.CreateNewAt(num)
            for each col in CurrentObject.columns 
          
            if col.DataType="" then 
                 	col.Name="修改人"
                 	col.Code="modify_user_id"
                 	col.Comment="修改人"
                 	col.DataType="bigint(20)"     
            end if 
            next
            num=num+1
         end if
         
         
         if modify_time_=1 then 
            CurrentObject.columns.CreateNewAt(num)
            for each col in CurrentObject.columns 
          
            if col.DataType="" then 
                 	col.Name="修改时间"
                 	col.Code="modify_time_"
                 	col.Comment="修改时间"
                 	col.DataType="datetime"
		col.DefaultValue="CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            end if 
            next
            num=num+1
         end if
         

		 if is_delete_=1 then 
            CurrentObject.columns.CreateNewAt(num)
            for each col in CurrentObject.columns 
          
            if col.DataType="" then 
                 	col.Name="删除标志"
                 	col.Code="is_delete_"
                 	col.Comment="删除标识(1:已删除;0:正常)"
                 	col.DataType="tinyint(1)"
		col.DefaultValue="0"
            end if 
            next
            num=num+1
         end if
				 
      if is_final_=1 then 
            CurrentObject.columns.CreateNewAt(num)
            for each col in CurrentObject.columns 
          
            if col.DataType="" then 
                 	col.Name="修改标志"
                 	col.Code="is_final_"
                 	col.Comment="是否不可修改(1:不可修改;0:可修改)"
                 	col.DataType="tinyint(1)"
		col.DefaultValue="0"
            end if 
            next
            num=num+1
         end if
         
      if tenant_id_=1 then 
            CurrentObject.columns.CreateNewAt(num)
            for each col in CurrentObject.columns 
          
            if col.DataType="" then 
                 	col.Name="租户id"
                 	col.Code="tenant_id_"
                 	col.Comment="租户id"
                 	col.DataType="bigint(20)"
		col.DefaultValue="-1"
            end if 
            next
            num=num+1
         end if
         
      if team_id_=1 then 
            CurrentObject.columns.CreateNewAt(num)
            for each col in CurrentObject.columns 
          
            if col.DataType="" then 
                 	col.Name="团队id"
                 	col.Code="team_id_"
                 	col.Comment="团队id"
                 	col.DataType="bigint(20)"
            end if 
            next
            num=num+1
         end if
         
      end if      
End Sub

添加注释

Option   Explicit     
ValidationMode   =   True     
InteractiveMode   =   im_Batch  
Dim blankStr  
blankStr   =   Space(1)  
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 = "" or replace(col.comment," ", "")="" Then  
                        col.name = blankStr  
                        blankStr = blankStr & Space(1)  
                  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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lastinglate

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值