Author Topic: How to get the name of the linked elements  (Read 5327 times)

Stenvang

  • EA User
  • **
  • Posts: 50
  • Karma: +0/-0
    • View Profile
How to get the name of the linked elements
« on: September 08, 2014, 10:06:53 pm »
I want to get the names of the relationships an element has in my project. For now it seems to me that this must be in the connector collection but I can't seem to find it there. Any help?
Am I looking in the wrong collection or is it just me?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to get the name of the linked elements
« Reply #1 on: September 09, 2014, 05:10:07 am »
You need to iterate element.Connectors and there Name is the property of the connector.

q.

Stenvang

  • EA User
  • **
  • Posts: 50
  • Karma: +0/-0
    • View Profile
Re: How to get the name of the linked elements
« Reply #2 on: September 09, 2014, 06:32:21 pm »
Iterating through element.Connecters and writing the property out in a string just gives me "System.__ComObject" and not the name of the element connected to the element I was iterating through.
At first I thought it was the Connector.Name but that obviously gives me the name of the connector and not the name of the element connected to it.

It seems strange to me that their isn't a method for returned the "Source" or "Target" in the Connector collection cause you can find everything else in there like the name, alias, style, direction and so on..
« Last Edit: September 09, 2014, 07:02:47 pm by Stenvang »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to get the name of the linked elements
« Reply #3 on: September 09, 2014, 07:56:56 pm »
First you asked for the connector name, not the name of the connected element. Which now?

q.

Stenvang

  • EA User
  • **
  • Posts: 50
  • Karma: +0/-0
    • View Profile
Re: How to get the name of the linked elements
« Reply #4 on: September 09, 2014, 08:41:15 pm »
Sorry for the misleading but it was actually the name of the connected element I wanted.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to get the name of the linked elements
« Reply #5 on: September 09, 2014, 10:12:49 pm »
The connected element is found by retrieving conector.SupplierID and .ClientID. Both are object ids and you need to use Repository.GetElementById to get the object with the Name property. Note that you need to check which element is the opposite by comparing to the main element's object id (if it's Supplier check Client and vice versa).

q.

Stenvang

  • EA User
  • **
  • Posts: 50
  • Karma: +0/-0
    • View Profile
Re: How to get the name of the linked elements
« Reply #6 on: September 09, 2014, 10:36:32 pm »
Ty!

I've posted the code in c# here if anyone needs it:

           foreach (Connector c in element.Connectors)
            {
                var supplierID = c.SupplierID;
                var clientID = c.ClientID;

                Element supplierElement = eaRepo.GetElementByID(supplierID);
                Element supplierClient = eaRepo.GetElementByID(clientID);

                if (!elm.Name.Equals(supplierElement.Name))
                {
                }
                if (!elm.Name.Equals(supplierClient.Name))
                {
                }
            }

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to get the name of the linked elements
« Reply #7 on: September 09, 2014, 11:12:21 pm »
Better compare the object IDs rather than the names since the latter are not unique.

q.

Wade Brooks

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: How to get the name of the linked elements
« Reply #8 on: September 18, 2014, 05:16:29 am »
I have a very similar question. I have a requirement linked to a class, I then used the  "link to element feature" to link it to a class member.  The automation interface shows it is linked to the class.   How do I find what member function it may be linked to.    And how do you link to a member function inside a class with the automation interface?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to get the name of the linked elements
« Reply #9 on: September 18, 2014, 06:32:28 am »
Though the name of the thread is similar to your question it's actually something completely different. Start a thread "Get Linked Element Feature via API" or the like and I'll try to answer.

q.