TriX
TriX

Reputation: 45

Not able to use AttachLinkObject in PDM with Python

Recently I started to try make automatically PowerDesigner Models with Python, because I am most familiar with language and I need to connect to database, transform data etc. I used win32com.client to execute PowerDesigner and I can successfully rename Model name, package name and Diagram name, then I am able to create task as specific stereotypes, fill them with the right data.

But the part where I am not able to continue is Links. One of my colleagues sent me their code they used in PD that works for them:

Set object1 = wfl_package.FindChildByName(rel_object1_name, cls_ExtendedObject)

But I am not able to access or I don't know how to access cls_ExtendedObject. So I tried different way to go, so I did this:

    # PD inicialization
    PD_App = win32com.client.Dispatch("PowerDesigner.Application")
    PD_Model = PD_App.OpenModel(PD_Model_Path)

    Package = PD_Model.Packages.Item(0)
    Diagram = Package.PhysicalDiagrams.Item(0)

    # Link test
    start_task_link = Package.ExtendedLinks.CreateNew()
    start_task_link.Stereotype = 'Predecessor'
    start_task_link.Object1 = Package.Children.Item(0) # <- Getting the right object
    start_task_link.Object2 = Package.Children.Item(1) # <- Getting the also right object
    Diagram.AttachLinkObject(start_task_link)

But I am getting error:

TypeError: The Python instance cannot be converted to a COM object

I tried how will the generation look likes when I comment out the AttachLinkObject and I could see the link created between two tasks, but not visually visible... I also tried to initialize the library with different types, but unsuccessful :(

Would someone know what I am doing badly and should change?

Please if someone know, I would be very glad about help.

Upvotes: 0

Views: 28

Answers (0)

Related Questions