Extending the Metamodel by Script

When you import a file using scripts, you can import as extended attributes or extended collections some properties that may not correspond to standard attributes.

In the following example, we:

Example

If not ExistingModel Is Nothing Then
 ' Creating a new extension
 Dim ModelExtension
 Set ModelExtension = ExistingModel.ExtendedModelDefinitions.CreateNew()
 If not ModelExtension is Nothing Then
  output "Model extension successfully created in model"
  ' Initialize model extension attributes
  ModelExtension.Name = "Extension for Import of XXX files"
  ModelExtension.Code = "importXXX"
  ModelExtension.Family = "Import"
  ' Defines a new Stereotype for the Class metaclass in the profile section
  Dim MySttp
  Set MySttp = ModelExtension.AddMetaExtension(PdOOM.Cls_Class, Cls_StereotypeTargetItem)
  If not MySttp Is Nothing Then
   output "Stereotype extension successfully created in extension"
   MySttp.Name = "MyStereotype"
   MySttp.UseAsMetaClass = true ' The stereotype will behave as a new metaclass (specific list and category in browser)
   ' Defines an extended attribute for this stereotype
   Dim MyExa
   Set MyExa = MySttp.AddMetaExtension(Cls_ExtendedAttributeTargetItem)
   If not MyExa is Nothing Then
    output "Extended Attribute successfully created in extension"
    MyExa.Name = "MyAttribute"
    MyExa.Comment = "custom attribute coming from import"
    MyExa.DataType = 10  ' This corresponds to integer
    MyExa.Value = "-1" ' This is the default value
    Set MyExa = Nothing
   End If
   ' Defines an extended collection for this stereotype
   Dim MyExCol
   Set MyExCol = MySttp.AddMetaExtension(Cls_ExtendedCollectionTargetItem)
   If not MyExCol is Nothing Then
    output "Extended collection successfully created in extension"   
    MyExCol.Name = "MyCollection"
    MyExCol.Comment = "custom collection coming from import"
    MyExCol.DestinationClassKind = PdOOM.Cls_class  ' The collection can store only classes
    MyExCol.Destinationstereotype = "MyStereotype"  ' The collection can store only classes with stereotype "MyStereotype"
    Set MyExCol = Nothing
   End If
   Set MySttp = Nothing
  End If
  Set ModelExtension = Nothing
 End If
End If