cancel
Showing results for 
Search instead for 
Did you mean: 

Create Reference Between 2 table

velurani
Explorer
0 Kudos

Hi All

I was creating a script fro creating refrences between 2 tables using Script . I tried the below code

    

             Set Model = PD.OpenModel("D:\test.pdm")

             Set tab=      Model.FindChildByName("Emp", PdPDM.cls_Table, "", Nothing, False, False)

  Now  I want to create a refrence beterween emp and dept . I tried the below script

             Set ref = tab.OutReferences.CreateNew(PdPDM.cls_Reference)    

  but it gives errors . I found that the below scripts works for creating new entities

                Set tabobject = Model.Entities.CreateNew(cls_Entity)

How to create a reference between 2 tables using the script. Thanks for the help 

Ani

Accepted Solutions (1)

Accepted Solutions (1)

marc_ledier
Active Participant
0 Kudos

Hi,

The OutReferences is not a composition Under table. Therefore, you cannot create the reference as a direct child of the table (because it is not in a metamodel point of view).

Instead you must create the reference Under the model

* set ref = Model.References.CreateNew()

and then attach the child and parent table

* set ref.ParentTable = tab

* set ref.ChildTable = chld

(having chld being the child table you want to attach with reference)

Regards,

Marc

velurani
Explorer
0 Kudos

Marc

Thanks . It works . one problem is , The relationship is not shown on the digram . How can it shown on the diagram

Ani

marc_ledier
Active Participant
0 Kudos

Hi,

You need to use the AttachLinkObject function on the diagram (check the chm help).

To get diagram, you can use ActiveDiagram global property (you need to check that model matches) or use Model.DefaultDiagram, or find the diagram where the table is already displayed.

Marc

Answers (0)