Accessing Collections of Sub-Objects or Related Objects

An OOM contains a collection of classes and classes contain collections of attributes and operations. To iterate over a collection, use the .foreach_item macro.

Example
%Name% contains:
.foreach_item(Widgets)
	\n\t%Name% (%Color% %Shape%)
.next
Result:
MyObject contains:
	Widget1 (Red Triangle)
	Widget2 (Yellow Square)
	Widget3 (Green Circle)

Standard collections defined in the PowerDesigner public metamodel (see The PowerDesigner Public Metamodel) are referenced using their public names, which are written in CamelCase. You can infer public names for many collections from their labels in object property sheet tabs, but in case of doubt, click the Property Sheet Menu button at the bottom of the property sheet and select Find in Metamodel Objects Help to review all available collections for the object.

Extended collections (see Extended Collections and Compositions (Profile) and Calculated Collections (Profile)) are referenced by their Name.

You can use the following keywords to access information about a collection:

Name

Description

First

(object) Returns the first element of the collection.

IsEmpty

(boolean) Returns True if the collection is empty, or false if it contains one or more members.

Count

(integer) Returns the number of elements in the collection. You can use this keyword for defining criteria based on collection size, for example Attributes.Count>=10.

Example
%Name% is associated with %AttachedRules.Count% business rules,
 of which the first is %AttachedRules.First.Name%.
Result:
myClass is associated with 3 business rules,
 of which the first is myRule.