如何通过VB将扩展属性添加到数据项

时间:2018-05-09 08:06:20

标签: powerdesigner

我正在尝试通过VBS将excel电子表格导入PD来创建CDM。

1 - 加载电子表格 2 - 创建CDM 3 - 使用扩展属性创建数据项。

我可以加载并创建CDM,并创建数据项,只要我没有扩展属性,但我不能在VBS中创建扩展属性 - 但需要创建扩展属性以加载其余的电子表格。任何想法。

代码目前看起来像:

> Option Explicit
> 
> InteractiveMode = im_Dialog
> 
> Dim Model, objExcel, objWorkbook, intRow, LogFile, lobj, MyExa Set
> Model = ActiveModel Dim MyModel, t, r, sym set MyModel =
> CreateModel(PdCDM.Cls_Model,"DBMS=SYASA12")
> 

> 
> Set objExcel = CreateObject("Excel.Application") Set objWorkbook =
> objExcel.Workbooks.Open ("C:\Users\ Models\09.
> Dictionary\DataDictionaryTestImport.xlsx")
> 
> intRow = 2
> 
> DIM Name, Stewards, LongDescription, ParentCategory,
> DomainSubCategory,  BusinessUnit, BusinessUnitArea,
> BusinessUnitDepartment, Calculations, DataOwner, ValidationRule,
> DataQualityBusinessRules, Format, SourceSystemName, 
> GoldenSourceSystem, ElementType DIM v_tp
> 
> 
> Do Until objExcel.Cells(intRow,1).Value = ""    Name              = 
> objExcel.Cells(intRow, 1).Value    Stewards       =  objExcel.Cells(intRow,
> 2).Value    LongDescription       =  objExcel.Cells(intRow, 3).Value   
> ParentCategory    =  objExcel.Cells(intRow, 4).Value   
> DomainSubCategory =  objExcel.Cells(intRow, 5).Value   
> BusinessUnit      =  objExcel.Cells(intRow, 6).Value   
> BusinessUnitArea          =  objExcel.Cells(intRow, 7).Value   
> BusinessUnitDepartment    =  objExcel.Cells(intRow, 8).Value   
> Calculations      =  objExcel.Cells(intRow, 9).Value    DataOwner     = 
> objExcel.Cells(intRow, 10).Value    DataQualityBusinessRules  = 
> objExcel.Cells(intRow, 11).Value    ValidationRule    = 
> objExcel.Cells(intRow, 12).Value    Format        =  objExcel.Cells(intRow,
> 13).Value    SourceSystemName         =  objExcel.Cells(intRow, 14).Value   
> GoldenSourceSystem    =  objExcel.Cells(intRow, 15).Value   
> ElementType   =  objExcel.Cells(intRow, 16).Value
>        Set t=MyModel.dataitems.CreateNew()
>        t.Name             =  objExcel.Cells(intRow, 1).Value
>     CreateAttributes t
>       Logger LogFile, Year(Date) & "-" & Month(Date) & "-" & Day(Date) & " " & Time & " - Object: " & name
>        intRow = intRow + 1    loop
>        'Create Data Items For idx = 1 to 12
>     Next
>      
>       'Log file Sub Logger (LogFilename, LogText)     Dim fso     Dim LogFile         Set fso = CreateObject("Scripting.FileSystemObject")    Set
> LogFile = fso.OpenTextFile(LogFilename, 8, True)  LogFile.WriteLine
> LogText    End Sub
> 
> 
> Function CreateAttributes(t)  Dim attr  Set attr =
> t.CreateObject(Pdcdm.cls_Attribute)    t=MyModel.dataitems.CreateNew()
> attr.Name = "ID"  attr.Code = "ID"  attr.DataType = "int" 
> attr.Persistent = True  attr.PersistentCode = "ID" 
> attr.PersistentDataType = "I"  attr.PrimaryIdentifier = True  Set attr
> = t.CreateObject(Pdcdm.cls_Attribute)  attr.Name = "Name"  attr.Code = "Name"  attr.DataType = "String"  attr.Persistent = True 
> attr.PersistentCode = "NAME"  attr.PersistentDataType = "A30"
> 
>  CreateAttributes = True End Function

1 个答案:

答案 0 :(得分:0)

我想你想设置一个与你选择的Sybase SQL Anywhere 12 DBMS相关的扩展属性。

你应该把它写成:

  

obj.SetExtendedAttribute" SYASA12.CastDataType",value

我想如果你没有指定目标代码,它会假定扩展属性是在当前模型中定义的,而不是在某些外部模型/目标中定义的。

..实际上,引用" SAP PowerDesigner Scripting" (安装目录中的pdvbs.chm):

  

更改由其标识的扩展属性的值   限定名称 - 以。为前缀的扩展属性的名称   定义它的GenerationTarget对象的代码。对于   示例:" MyGenerationTarget.MyExtendedAttribute"。

在发货目标中,这写为obj.SetExtendedAttribute "%CurrentTargetCode%.CastDataType", value,其中%CurrentTargetCode%在准备和执行VBscript之前被实际目标代码替换。

如果扩展属性不是text类型,则可以使用SetExtendedAttributeText进行尝试,并使用从文本到实际属性类型的自动转换。