You should generally create objects via the collection under the parent object using the CreateNew() method. The CreateObject(kind) method is also available on model objects.
Dim MyModel Set MyModel = ActiveModel Dim MyClass ' Create a class Set MyClass = MyModel.Classes.CreateNew() If MyClass is nothing Then ' Display an error message box msgbox "Fail to create a class", vbOkOnly, "Error" Else output "The class has been created." ' Set Name, Code, Comment, Stereotype and Final attributes MyClass.SetNameAndCode "Customer", "cust" MyClass.Comment = "Created by script" MyClass.Stereotype = "MyStereotype" MyClass.Final = true ' Create an attribute inside the class Dim MyAttr Set MyAttr = MyClass.Attributes.CreateNew() If not MyAttr is nothing Then output "The attribute has been created." MyAttr.SetNameAndCode "Name", "custName" MyAttr.DataType = "String" ' Reset the variable in order to avoid memory leaks End If End If
Dim MyModel Set MyModel = ActiveModel Dim MyClass ' Create a class Set MyClass = MyModel.CreateObject(cls_Class) MyClass.SetNameAndCode "Another Class", "Class2" MyClass.Comment = "Created by CreateObject"
Dim MyModel Set MyModel = ActiveModel Dim MyFirstClass, MySecondClass, MyAssociation ' Create classes Set MyFirstClass = MyModel.Classes.CreateNew() MyFirstClass.SetNameAndCode "Class1", "C1" Set MySecondClass = MyModel.Classes.CreateNew() MySecondClass.SetNameAndCode "Class2", "C2" ' Create association Set MyAssociation = MyModel.Associations.CreateNew() MyAssociation.Name = "A1" ' Define its extremities Set MyAssociation.Object1 = MyFirstClass Set MyAssociation.Object2 = MySecondClass