Skip to Content
author's profile photo Former Member
Former Member

Reuse entity attributes by script


I'm trying to reuse some data items by an event handler using script.

Fore example, i have a table : Table1{id,name,adress}, when i create a new table, the initilize script add all attributes of Table1 in this new table, so i have new_table{id,name,adress}.

Now the problem is when i drop Table2, i loose attributes of Table1.

Is there a function which allow us to reuse attributs ? Because i searched in the metamodel help file without any result

Thank you

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Posted on Dec 16, 2013 at 09:49 PM

    If you copied the columns from table 1 to table 2, I can't see why they'd be deleted from table 1 when you delete table 2.

    The PD way of 'reusing' columns is called replication. You can also use column denormalisation.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thank you George,

      Sorry i used the term 'Table' but in reality i'm working on a CDM and using entities. In this case i cant use column denormalization, and the aim of using a reuse is to avoid copy the same data item two times.

      If you open the Entity Properties window, in the attributes Tab, there is an icone to reuse data items (The fifth one from left side).

      I want to do the same thing by script.

  • Posted on Jan 07, 2014 at 03:42 PM


    most likely what you did was not making new attributes but copy the "pointer" from Ent1 to ent2 ,

    here is some code which should work:

    Option Explicit

    Dim pd_App As PdCommon.application

    Function copy_table(thename As String, newname As String)

    Set pd_App = New PdCommon.application

    Dim InputModel As PdCDM.model
    Set InputModel = pd_App.OpenModel("U:\PD_Modelle\cdmtest.cdm")

    Dim tc, t As PdCDM.Entity
    Dim col As PdCommon.ObjectBag

    Debug.Print InputModel.DataItems.Count

    Set col = InputModel.GetCollectionByName("Entities")

    For Each t In col
    Output ">" & t.Code

    If t.Code = thename Then
    Dim a, ac As PdCDM.EntityAttribute
    Set tc = InputModel.Entities.CreateNew(cls_Entity)
    tc.Code = newname
    For Each a In t.Attributes
    Set ac = tc.Attributes.CreateNew(cls_EntityAttribute)
    ac.SetNameAndCode a.Code, a.Code

    '' copy here other stuff u need !

    Next a
    Output "ec-->" & & " - " & tc.ClassName & tc.UOL
    End If

    Next t

    End Function

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 09, 2014 at 09:46 AM

    Why not copy the complete table in this case?

    If you like to have always a "default" table you can do this with the script below

    dim T1,mdl

    set mdl = Activemodel

    Set T1 = mdl.tables.item(0)

    Dim pSel

    set pSel = mdl.CreateSelection()

    pSel.Objects.Add T1



    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 10, 2014 at 10:50 AM

    Thank you guys for your answers.

    I think that i didn't explain well my needs.

    I don't want to copy an entity to another, neither create new attributes. I have some attributes which are common between all my entities, until now, for each new entity, i use the reuse data items button to add those attributes, but now i want to make it simple and faster. So i created an event handler on my entities, and i want to reuse those data items and not create new attributes with the same code and name and comment ...

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member dirk jaeckel

      My code is :

      Function %Initialize%(obj)

      For each T in ActiveModel.Entities

      If T.Code = "Items_Entity" Then

      For each col in T.Attributes

      Set new_attr = obj.Attributes.CreateNew(col)



      End If


      %Initialize% = True

      End Function

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.