如何通过 VB 向数据项添加扩展属性
How to add extended attribute via VB to a data item
我正在尝试通过 VBS 将 excel 价差 sheet 导入 PD 来创建 CDM。
1 - 加载传播 sheet
2 - 创建 CDM
3 - 创建具有扩展属性的数据项。
我可以加载和创建 CDM,并创建数据项,只要我没有扩展属性,但是我无法在 VBS 中创建扩展属性 - 但需要创建扩展属性才能加载其余价差 sheet。任何想法。
代码目前看起来像:
> 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.
> 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
我猜您想设置一个与您选择的 Sybase SQL Anywhere 12
DBMS 相关的扩展属性。
你应该写成:
obj.SetExtendedAttribute "SYASA12.CastDataType", value
我猜如果你不指定目标代码,它假定扩展属性是在当前模型中定义的,而不是在某些外部model/target。
..其实引用一下"SAP PowerDesigner Scripting"(安装目录下的pdvbs.chm):
Changes the values of an extended attribute, identified by its
qualified name - the name of the extended attribute prefixed by the
code of the GenerationTarget object on which it is defined. For
example: "MyGenerationTarget.MyExtendedAttribute".
在发布的目标中,这写成 obj.SetExtendedAttribute "%CurrentTargetCode%.CastDataType", value
,其中 %CurrentTargetCode%
在准备和执行 VBscript 之前被实际的目标代码替换。
如果扩展属性不是文本类型,可以使用SetExtendedAttributeText 来尝试,使用文本到实际属性类型的自动转换。
我正在尝试通过 VBS 将 excel 价差 sheet 导入 PD 来创建 CDM。
1 - 加载传播 sheet 2 - 创建 CDM 3 - 创建具有扩展属性的数据项。
我可以加载和创建 CDM,并创建数据项,只要我没有扩展属性,但是我无法在 VBS 中创建扩展属性 - 但需要创建扩展属性才能加载其余价差 sheet。任何想法。
代码目前看起来像:
> 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.
> 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
我猜您想设置一个与您选择的 Sybase SQL Anywhere 12
DBMS 相关的扩展属性。
你应该写成:
obj.SetExtendedAttribute "SYASA12.CastDataType", value
我猜如果你不指定目标代码,它假定扩展属性是在当前模型中定义的,而不是在某些外部model/target。
..其实引用一下"SAP PowerDesigner Scripting"(安装目录下的pdvbs.chm):
Changes the values of an extended attribute, identified by its qualified name - the name of the extended attribute prefixed by the code of the GenerationTarget object on which it is defined. For example: "MyGenerationTarget.MyExtendedAttribute".
在发布的目标中,这写成 obj.SetExtendedAttribute "%CurrentTargetCode%.CastDataType", value
,其中 %CurrentTargetCode%
在准备和执行 VBscript 之前被实际的目标代码替换。
如果扩展属性不是文本类型,可以使用SetExtendedAttributeText 来尝试,使用文本到实际属性类型的自动转换。