Browsing and Modifying Collections (Scripting)

Most metamodel navigation is performed by descending from the model root through collections of objects to collections of sub-objects or associated objects. An OOM contains a collection of classes and classes contain collections of attributes and operations. You can obtain information about and browse the members of a collection through scripting, as well as adding, removing, and moving objects in the collection.

To browse the members of a collection, navigate to the parent object and then use a For each loop. This script prints the names of all the tables in an open PDM:
Dim MyModel
Set MyModel=ActiveModel
For each t in MyModel.Tables
    Output "* " & t.Name
Next
When you browse a collection, both full objects in the collection and any shortcuts will be retrieved.
Note: For information about accessing collections defined in extensions, see Creating and Accessing Extensions (Scripting).
The following kinds of collections appear in the metamodel:
The following properties are available for all collections:
The following methods are available for modifying writeable collections:
The following script:
Dim MyModel, t, r, sym
set MyModel = CreateModel(PdPDM.Cls_Model,"DBMS=SYASA12")
MyModel.SetNameAndCode "MyPDM" , "MyPDM"
'Create tables and rules
For idx = 1 to 12
   Set t=MyModel.Tables.CreateNew()
   t.SetNameAndCode "T" & idx, "T" & idx
   Set sym=ActiveDiagram.AttachObject (t)
   Set r=MyModel.BusinessRules.CreateNew()
   r.SetNameAndCode "BR" & idx, "BR" & idx
Next
ActiveDiagram.AutoLayoutWithOptions(2)
'Attach rules to Table 1
   Dim MyTable
   Set MyTable=MyModel.FindChildByName("T1",cls_table)
   For idx = 1 to 10
      MyTable.AttachedRules.Add(MyModel.FindChildByName("BR" & (idx),cls_businessrule))
   Next
'Print list of rules attached to Table 1
Output "Rules Attached to T1 (" & MyTable.AttachedRules.Count & ")"
For each r in MyTable.AttachedRules
    Output "* " & r.Name
Next
'Modify attached rules by insertion, move and removal
MyTable.AttachedRules.Insert 3, MyModel.FindChildByName("BR12",cls_businessrule)
MyTable.AttachedRules.Move 5,0
MyTable.AttachedRules.Remove(MyModel.FindChildByName("BR6",cls_businessrule))
'Print modified list of rules
Output "Modified Rules Attached to T1 (" & MyTable.AttachedRules.Count & ")"
For each r in MyTable.AttachedRules
    Output "* " & r.Name
Next