Creating Mappings Between Objects (Scripting)

You can create data sources in a model and from there create mappings from source objects in other models to objects in the first model using scripts.

The following script creates an OOM and a PDM, populates them with classes and tables, then creates a data source in the OOM, associates the PDM with it and creates mappings:
Dim MyOOM, MyPDM
'Create an OOM and a PDM
set MyOOM = CreateModel(PdOOM.Cls_Model, "|Language=Analysis|Diagram=ClassDiagram|Copy")
MyOOM.SetNameAndCode "MyOOM", "OOM"
set MyPDM = CreateModel(PdPDM.Cls_Model, "|DBMS=Sybase SQL Anywhere 12|Copy")
MyPDM.SetNameAndCode "MyPDM", "PDM"
 'Create classes and tables
 For idx = 1 to 6
   Set c=MyOOM.Classes.CreateNew()
   c.SetNameAndCode "Class" & idx, "C" & idx
   Set t=MyPDM.Tables.CreateNew()
   t.SetNameAndCode "Table" & idx, "T" & idx
Next
'Create a data source in the OOM and add the PDM as its source
Dim ds, m1
Set ds = MyOOM.DataSources.CreateNew()
ds.SetNameAndCode "MyPDM", "PDM"
ds.AddSource MyPDM

'Create a mapping between C1 and T6
set m1 = ds.CreateMapping(MyOOM.FindChildByName("Class1",cls_class))
m1.AddSource MyPDM.FindChildByName("Table6",cls_table)
' Retrieve mappings for each class in the OOM
 For each c in MyOOM.Classes
   Dim m, sc
   set m = ds.GetMapping(c)
   If not m is nothing then
      Output c.Name & vbtab & "Mapped to: "
      for each sc in m.SourceClassifiers
         output vbtab & vbtab & "- " & sc.Name
      next
   Else
      Output c.Name & vbtab & "No mapping defined."
   End if
Next

For more information about objects mapping, see Core Features Guide > Linking and Synchronizing Models > Object Mappings.