cancel
Showing results for 
Search instead for 
Did you mean: 

Function for Get a specific entity from Entity Collection

velurani
Explorer
0 Kudos

Hi All

I found there is a function for retrieving the specific object collection from the Model 

Dim Mdl As PdCommon.BaseModel

    Set PD = CreateObject("PowerDesigner.Application")

    PD.OpenModel ("D:\PowerDesigner\project.pdm"

For Each Mdl In PD.Models

    Debug.Print Mdl.Name

   Set ObjTab = Mdl.GetCollectionByName("Tables")

next

Is there is any function to get the specific object from the collection than iterating through the collection . For example . I want to get the emnployee table from the   ObjTab collection

Set emptab =ObjTab .<<< functionname >>("Employee")

I tried GetCollectionByName , but its not working

Thanks for help

Ani

Accepted Solutions (1)

Accepted Solutions (1)

marc_ledier
Active Participant
0 Kudos

Hi,

You can use the "FindChildByName" or "FindChildByCode" functions.

Marc

velurani
Explorer
0 Kudos

Marc

Thanks. I could not find that function in the help file . Am i Missing anything

Ani

former_member185199
Contributor
0 Kudos


Look in the help menu under metamodel objects help, its horrible structured but you will find it there

velurani
Explorer
0 Kudos

Marc

I tried ObjTab .FindChildByName("Employee") . Its not working

Ani

former_member185199
Contributor
0 Kudos

See my Article:

you can adopt it for your needs/objects, there is also a property to save the actual model (from activemodel) because when you open a new model in your code with a diagram that new one becomes the activemodel and your code can fail/show strange behaivor

dj

velurani
Explorer
0 Kudos

dj

Thanks. I glanced through the blog post. Requires time to understand it  properly since I am new to PD

Ani

former_member185199
Contributor
0 Kudos

using excel read this article

if it helps you, please vote it up and like it

Answers (1)

Answers (1)

phsilva
Explorer
0 Kudos

Hi Ani,

To use the functions that Marc and Dirk mentioned you need to provide other required values for the functions´ parameter.

Just to give you an example on how to use the function FindChildByName, let´s say you have a Physical Model (PDM). This type of model has a collection of tables, so to find a specific table using the function FindChildByName your lines of code should be:

dim tabObj

set tabObj = activeModel.FindChildByName("Employee", PdPDM.cls_table, "",Nothing, False, False)

activeModel - represents you currently opened PDM model in the example I provide here.

Using the metamodel do a search for FindChildByName. This function has an explanation about all parameters it has, what they mean and what are their default value (if it applies).

Hope it helps.

Regards

-Paulo

former_member185199
Contributor
0 Kudos


Silva,

does FindChildByName works for ExtendedObjects?

dj

velurani
Explorer
0 Kudos

Paulo

I am using the PD 15.x . I can not find the FindChildByName function in 15 . I tried below code . But shows error like the Object does not contains this property or method


Sub DoStuff()

    Dim PD As PdCommon.Application

    Dim Mdl As PdCommon.BaseModel

 

    Set PD = CreateObject("PowerDesigner.Application")

    PD.OpenModel ("D:\PowerDesigner\project.pdm")

   Set tabObj = PD.ActiveModel.FindChildByName("Employee", PdPDM.cls_Table, "", Nothing, False, False)

end sub

Ani

former_member185199
Contributor
0 Kudos

Declare Mdl  as PdEAM.Model !!!! (or dont declare a type )

velurani
Explorer
0 Kudos

I used directly  as below , still it did notwork

Set tabObj = PD.ActiveModel.FindChildByName("Employee", PdPDM.cls_Table, "", Nothing, False, False)

phsilva
Explorer
0 Kudos

Hi Ani,

Try the code below.

   Dim PD As PdCommon.Application

    Dim Mdl As PdPDM.Model

    Dim Tbl As PdPDM.Table

    Set PD = CreateObject("PowerDesigner.Application")

    Set Mdl = PD.OpenModel("D:\PowerDesigner\project.pdm")

    Set Tbl = Mdl.FindChildByName("Employee", PdPDM.cls_Table, "", Nothing, False, False)

    If Not Tbl Is Nothing Then

        PD.Output Tbl.Code   'check the result in PD´s output window

    End If

Check if your model is located in your "D\PowerDesigner" directory.

You said that you could not find the function in PD 15.x, maybe it became available in a newest PD version than one you are using. I know that in PD 12.5 that function does not exist.

I checked my old PD versions and the 15.2.x.x.x I have here, does have the function available.

HTH,

-Paulo

phsilva
Explorer
0 Kudos

Dirk,

Yes, it does! I have being work on some projects where I have used both the functions and extendedobjects a lot.

You can take the examples below and try it.

-PH

velurani
Explorer
0 Kudos

Thank you all for your reply . Your solution (FindChildByName) worked fine in PD 16.5