Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.

Topic
Prev Next

Collection Class

Collection is the main collection Class used by all elements within the Automation Interface. It contains methods to iterate through the collection, refresh the collection and delete an item from the collection.

It is important to realize that when AddNew is called, the item is not automatically added to the current collection. The typical steps are:

  • Call AddNew to add a new item
  • Modify the item as required
  • Call Update on the item to save it to the database
  • Call Refresh on the collection to include it in the current set

Delete is the same; until Refresh is called, the collection still contains a reference to the deleted item, which should not be called.

Each method can be used to iterate through the collection for languages that support this type of construct.

Collection Attributes

Attribute

Remarks

See also

Count

Short

Notes: Read only

The number of objects referenced by this list.

ObjectType

ObjectType

Notes: Read only

Distinguishes objects referenced through a Dispatch interface.

ObjectType

Collection Methods

Method

Remarks

See also

AddNew(string Name,
string Type)

Object

Notes: Adds a new item to the current collection.

The interface is the same for all collections; you must provide a Name and Type argument. What these arguments are used for depends on the actual collection being accessed. For example, when adding a new element to the Elements collection, the Type string can be either a basic UML element type or a fully qualified element type (stereotype) defined by a profile, such as SysML::Requirement, differentiating it from a standard requirement.

Also note that you must call Update() on the returned object to complete the AddNew. If Update() is not called the object is left in an indeterminate state.

Parameters:

  • Name: String
  • Type: String (up to 30 characters long)
The AddNew Function

Delete(short index)

Void

Notes: Deletes the item at the selected reference.

Parameters:

  • index: Short

DeleteAt(short index, boolean Refresh)

Void

Notes: Deletes the item at the selected index. The second parameter is currently unused.

Parameters:

  • index: Short
  • Refresh: Boolean

GetAt(short index)

Object

Notes: Retrieves the array object using a numerical index. If the index is out of bounds, an error occurs.

Parameters:

  • index: Short

GetByName(string Name)

Object

Notes: Gets an item in the current collection by name. Supported for Model, Package, Element, Diagram and element TaggedValue collections.

If the collection does not contain any items (or, for the Tagged Value collection, if the collection contains items but the method cannot locate an object with the specified name) the method returns a null value. For other collections, if the method is unable to find an object with the specified name, it raises an exception.

Parameters:

  • Name: String
Diagram Class TaggedValue Class Element Class Package Class

GetLastError()

String

Notes: Returns a string value describing the most recent error that occurred in relation to this object.

Refresh()

Void

Notes: Refreshes the collection by re-querying the model and reloading the collection. Should be called after adding a new item or after deleting an item.

Update()

Boolean

Notes: Updates the current Collection object after modification or appending a new item.

If False is returned, check the 'GetLastError()' function for more information.