Skip to Content

Creating an extended attribute in PD using VBS

May 09 at 09:55 AM


avatar image


Am trying to create an extended attribute within PD using vbs

It fails on line:

Set attr = Createobject(model.cls_ExtendedAttribute)

Object not supported - does anyone know how to create a new extended atrribute in a dataitem?

Thank you

Code looks like

ValidationMode = True 'Forces PowerDesigner to validate 
' actions and return errors in the event of a forbidden action
InteractiveMode = im_Batch ' Supresses PowerDesigner dialogs
' Main function
' Create an OOM model with a class diagram
Dim Model
Set model = CreateModel(PdCDM.cls_Model, "|Diagram=ClassDiagram")
model.Name = "Customer Management"
model.Code = "CustomerManagement"
' Get the class diagram
Dim diagram
 Dim cls
 Set cls = model.dataitems.CreateNew()
 cls.Name = "Customer"
 cls.Code = "Customer"
 cls.Comment = "Customer class"
 cls.Description = "The customer class defines the attributes and behaviors of a customer."
 ' Create attributes
 CreateAttributes cls
 ' Create methods
 CreateOperations cls
 ' Create a symbol for the class
 Dim sym
 Set sym = diagram.AttachObject(cls)
 CreateClasses = True
' Create attributes function
Function CreateAttributes(cls)
 Dim attr
 Set attr = Createobject(model.cls_ExtendedAttribute)
 attr.Name = "ID"
 attr.Code = "ID"
 attr.DataType = "int"
 attr.Persistent = True
 attr.PersistentCode = "ID"
 attr.PersistentDataType = "I"
 attr.PrimaryIdentifier = True
 Set attr = cls.CreateObject(PdOOM.cls_Attribute)
 attr.Name = "Name"
 attr.Code = "Name"
 attr.DataType = "String"
 attr.Persistent = True
 attr.PersistentCode = "NAME"
 attr.PersistentDataType = "A30"
 Set attr = cls.CreateObject(PdOOM.cls_Attribute)
 attr.Name = "Phone"
 attr.Code = "Phone"
 attr.DataType = "String"
 attr.Persistent = True
 attr.PersistentCode = "PHONE"
 attr.PersistentDataType = "A20"
 Set attr = cls.CreateObject(PdOOM.cls_Attribute)
 attr.Name = "Email"
 attr.Code = "Email"
 attr.DataType = "String"
 attr.Persistent = True
 attr.PersistentCode = "EMAIL"
 attr.PersistentDataType = "A30"
 CreateAttributes = True
End Function
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

5 Answers

Best Answer
Phillip Lam
May 17 at 06:19 PM

ctempcapture.pngMore code.

Open your CDM. Run the following code

Set MyExt = ActiveModel.ExtendedModelDefinitions.CreateNew()
MyExt.Name = "MyExtension"
MyExt.Code = "MyExtension"
'Create extended attribute for dataItem
Set extendedAttributeObj = MyExt.AddMetaExtension(PdCDM.Cls_DataItem, Cls_ExtendedAttributeTargetItem) ="Business Unit"
extendedAttributeObj.code ="Business_Unit"
extendedAttributeObj.dataType = "12" ' 12 refers to String

Set extendedAttributeObj = MyExt.AddMetaExtension(PdCDM.Cls_DataItem, Cls_ExtendedAttributeTargetItem) ="Business Unit Area"
extendedAttributeObj.code ="Business_Unit_Area"
extendedAttributeObj.dataType = "12"

Note datatype should be assigned based on the following screenshot

ctempcapture.png (74.0 kB)
10 |10000 characters needed characters left characters exceeded
Ondrej Divis May 09 at 12:40 PM

Are you really sure, that you need to create an EXTENDED attribute? From your code it seems like you are trying to create another attribute inside a class and you are trying to set Datatype, Persistent and other properties in it. Your examples of class attributes are (ID, Name, Phone, etc.), but extended attribute is a new type of property for your object. For example: Class object has standard attributes like Name, Code, Comment, Description, etc. If you want to extend it with new property ("data steward name" for example), you should create extended attribute. Btw. it is much more common, that you create extended attributes manually (once) and use them automatically by script later (many times).

To sum it up:

  • Class attributes - objects inside your class, defining your class content (example: ID, Name, Phone, etc.)
  • Standard attributes (of a Class object) - DEFAULT properties describing your object (Name, Code, Comment, Description, Annotation, etc.)
  • Extended attributes - USER DEFINED properties describing your object (for example "business owner name" for your class)

Besides that, you are mixing OOM and CDM models and also mixing Class object and Dataitem object together. Such script cannot work.



Show 1 Share
10 |10000 characters needed characters left characters exceeded

Also, Data Items cannot have symbols, nor do they have attributes or operations as sub-objects.

Catherine Wreyford - tell us what your objective is, and we can help you. Are you sure the Excel or XMI imports don't do what you need?

Catherine Wreyford May 10 at 06:07 AM


What I am trying to do is (all through VBS) as I want to automate the process in a batch job

Create a CDM based on an excel spreadsheet

Create the data items that are listed in the excel spreadsheet

The data item has extended attributes that then need to be added.

If I were to do it manually - I would create a new CDM, create the extended attributes and then import the spreadsheet - have done this all manually and it works.

Issues that I have

I can create the CDM, and I can create the new data items - but not with extended attributes (because in a new CDM the extended attributes do not exist). Am not really a developer so trying to figure things out using the metamodel as much as possible, but there are no examples for creating an extended attribute within a data item

Show 3 Share
10 |10000 characters needed characters left characters exceeded

You don`t have to script this task by vbs. All you have to do is to use default Excel import functionality available in File - Import - Excel File... See attached screenshot. For importing your extended attributes you can define these extended attributes right during the import. Just use the "New..." button in the Excel import wizard during mapping the Excel column (containing extended attribute) to appropriate DataItem attribute.

The other way how to do it is to create your CDM manually, attach your already existing extension to it and the Excel import extension too. After that, you can run Excel import through context menu in the diagram and your extended attributes should be already available in the "Attribute" drop down list immediately (see the screenshot).



dataitems.jpg (258.2 kB)


The method that you mention is how I am doing it currently - but it is manual and there is no way that i can think of to automate it. By doing it in VBS I can automate it - hence the need for script rather


Hello Catherine - please refer to your earlier question about importing from Excel via a script.

Here's a possible process for you.

In a "specified place" accessible from the script, create a CDM that contains two things:

  • a model extension that contains the required extended attributes
  • the "Excel Import" extension - preferably embedded, not a shortcut
  • an Excel Import that works

The "specified place" could be

  • a windows or fileserver folder
  • your local "Templates" folder
  • a folder in the Repository (perhaps the Library)

In a script you could do the following (thinking out loud here, haven't tried it myself):

  1. Use the CreateModelFromTemplate method to create a new model based on the existing one - it'll be a clone
  2. In the new model's collection of Excel Imports (Extended Objects with "Excel Import" Stereotype), find the Excel Import
  3. Change the target Excel file if necessary
  4. Now run the "Import" method for the Excel Import (this may need to be qualified, as it's in the extension EXCEL_IMPORT, but
  5. Save the model - or check in to the repository directly

Steps 2-4 could be replaced with a custom script of course, in which case you don't need the Excel stuff in the model template. If you are using a custom script, the actual import method could be held in an extension in the model template - that way, the script you run automatically could be written in one of several languages.

Do you have any scripts that open and read Excel files?

Phillip Lam
May 11 at 09:15 PM
Show 1 Share
10 |10000 characters needed characters left characters exceeded


Had a look at the code - thank you. Issue is as follows:

I can created the extended attribute and stereotype as per code however it creates it as attached image:

What I am trying to do is:

So my issue is that I don't understand how the meta data model completely works. Using the code that I have:

Set MyExt = Model.ExtendedModelDefinitions.CreateNew() ********want to be able to say something like

**************************Set MyExt = Model.ExtendedDATAITEMDefinitions.CreateNew()

MyExt.Name = "IGC Extensions"
MyExt.Code = "IGC_Extensions"

****************************************************Don't need a sterotype for what I am doing************

'Create stereotype

Set MyStype = MyExt.AddMetaExtension(PdCDM.Cls_Model, Cls_extendedattributeTargetItem)

MyStype.Name = "Extended Attr"
MyStype.UseAsMetaClass = true
'Create extended attribute *************************this part is not an issue*************************
Set MyExAtt = MyStype.AddMetaExtension(Cls_ExtendedAttributeTargetItem)
MyExAtt.Name = "Stewards"
MyExAtt.Label = "Stewards"
MyExAtt.DataType = "12" ' (String) For a full list of values,

Not sure if I am making any sense.

pd-image-1.jpg (48.8 kB)
pd-img2.jpg (41.9 kB)
Phillip Lam
May 11 at 09:19 PM

In above page, click

Creating and Accessing Extensions (Scripting)

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thanks for the link, Phillip. On my machine, the whole script runs in less than 2 seconds, which is impressive :)

There are a couple of minor issues with the script as listed in Help:

  • I would not call the Extended Attribute "Type", as the Mobile Device object already has a Type property with its own list of values. In my version I called it "Tablet Type"
  • The script sets all values of Tablet Type to the default value, because there is a mistake in qualifying the name of the extended attribute in this command:
obj.SetExtendedAttribute "MYEXT.TabletType", myProps(2)

MYEXT needs to be changed to match the extension's Code