A collection within the Multiframe object model is a container for storing an ordered group of objects. It is essentially the equivalent of an array within VBA but its implementation has been encapsulated within an object. As such, it provides some methods and properties for accessing the items within the collection. The contents of a collection is not arbitrary, in fact its contents correspond directly to the components of a structural model. As such, adding an item to a collection adds a corresponding component the structure. For example, all the elements representing a frame are contained within an Elements collection object stored within the Frame object. Adding a new element to the frame is performed by adding a new element to the Elements collection.
All collection objects have a number of common properties and methods for manipulating their content. These are summarised in the tables below.
|
Property |
Type |
Description |
|
Count |
Long |
Read Only. Returns a number of items in list. |
|
Method |
Returns |
Description |
|
Addxxxx |
|
Add objects to list |
|
Find |
List Object |
Search items in list. |
|
Item |
Object |
Returns item in list. |
Collection objects have a single property, Count, which returns the number of objects contained within the collections.
Dim nEls as long
'Get number of elements in frame
nEls = mfApp.Frame.Elements.Count
’Tell user
MsgBox “Frame contains " & nEls & “ elements.”
Each collection object has a method for adding new items to the frame. The name of this method will vary from collection to collection but it will always begin with the word Add. For example, a new spring is added to the frame using the AddSpring method of the Springs collection. Most collections will also feature a method for adding multiple objects to the frame. These methods are named as the plural of the method for adding a single object to the frame. Continuing the previous example, a number of springs can be added to a frame using the AddSprings method of the Springs collection. The add methods associated with each collection are described earlier in this manual in the section associated with the objects contained by the collection.
An object within the collection is returned via the Item method.
Dim nEls as long
'Get number of elements in frame
With mfApp.Frame.Elements
.Item(1).Orientation = 45
End With
The Find method of a collection object is used to search the items in the collection for objects with properties matching a specified criterion. This method returns a list object containing the items meeting the criteria. This last section of this chapter describes this method in detail.