I am trying to create a CDM by importing an excel spread sheet into PD via VBS.
1 - Load the spread sheet 2 - Create CDM 3 - Create the data items With extended attributes.
I can load the and create the CDM, and create the data items, as long as I dont have extended attributes, however I cant create extended attributes in VBS - but need to create the extended attributes in order to load the rest of the spread sheet. Any ideas.
Code currently looks like:
> 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
I guess you want to set an extended attribute related to the Sybase SQL Anywhere 12
DBMS that you picked.
You should write it as:
obj.SetExtendedAttribute "SYASA12.CastDataType", value
I guess that if you don't specify the target code, it assumes that the extended attribute is defined in the current model, not in some external model/target.
.. in fact, to quote the "SAP PowerDesigner Scripting" (pdvbs.chm in the installation directory):
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".
In the shipped targets, this is written as obj.SetExtendedAttribute "%CurrentTargetCode%.CastDataType", value
where %CurrentTargetCode%
is replaced by the actual target code before the VBscript is prepared, and executed.
In case, the extended attribute is not of type text, you can use SetExtendedAttributeText to try, and use the automatic conversion from text to the actual attribute type.