Author Topic: SOLVED:Retrieve All Elements On A Diagram  (Read 13621 times)

priombiswas89

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
    • View Profile
Re: SOLVED:Retrieve All Elements On A Diagram
« Reply #15 on: December 15, 2020, 12:57:36 am »
Are you talking about selecting specific element or package, for example using the below documentation?

https://sparxsystems.com/enterprise_architect_user_guide/13.0/automation/objecttypeenum.html

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: SOLVED:Retrieve All Elements On A Diagram
« Reply #16 on: December 15, 2020, 01:02:37 am »
Are you talking about selecting specific element or package, for example using the below documentation?

https://sparxsystems.com/enterprise_architect_user_guide/13.0/automation/objecttypeenum.html
Yes, indeed.
That is a way to allow the user to select where to start.
If you are making an add-in you can add a context menu option to start your functionality.

Another option would be use to use the construct picker to let the user select an element.

Geert

priombiswas89

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
    • View Profile
Re: SOLVED:Retrieve All Elements On A Diagram
« Reply #17 on: December 15, 2020, 05:32:10 am »
Are you talking about selecting specific element or package, for example using the below documentation?

https://sparxsystems.com/enterprise_architect_user_guide/13.0/automation/objecttypeenum.html
Yes, indeed.
That is a way to allow the user to select where to start.
If you are making an add-in you can add a context menu option to start your functionality.

Another option would be use to use the construct picker to let the user select an element.

Geert

It is working with the following code, so far the package and element is working fine, except the diagram, I am trying to find a way to navigate to elements of diagram but so far haven't been succeeded:

Code: [Select]
                EA.Package pack;
                EA.Diagram diag;
                EA.Element ele;
                switch (Rep.GetContextItemType())
                {
                    case EA.ObjectType.otPackage:
                        {
                            pack = Rep.GetContextObject();
                            EA.Collection elements = pack.Elements;
                            foreach (EA.Element element in elements)
                            {
                                if (element.Type != "Trigger")
                                {
                                    packageNames.Add($"{element.Type} : {element.Name}");
                                }
                                foreach (EA.Connector item in element.Connectors)
                                {
                                    int clientId = item.ClientID;
                                    int supplierId = item.SupplierID;
                                    EA.Element clientElement = Rep.GetElementByID(clientId);
                                    EA.Element supplierElement = Rep.GetElementByID(supplierId);

                                    packageNames.Add($" From : {clientElement.Name}\n To: {supplierElement.Name}\n Trigger: {item.TransitionEvent}\n Effect: {item.TransitionAction}");
                                }
                            }
                            break;
                        }
                    case EA.ObjectType.otDiagram:
                        {
                            diag = Rep.GetContextObject();
                            foreach (EA.Element element in diag.DiagramObjects)
                            {
                                if (element.Type != "Trigger")
                                {
                                    packageNames.Add($"{element.Type} : {element.Name}");
                                }
                                foreach (EA.Connector item in element.Connectors)
                                {
                                    int clientId = item.ClientID;
                                    int supplierId = item.SupplierID;
                                    EA.Element clientElement = Rep.GetElementByID(clientId);
                                    EA.Element supplierElement = Rep.GetElementByID(supplierId);

                                    packageNames.Add($" From : {clientElement.Name}\n To: {supplierElement.Name}\n Trigger: {item.TransitionEvent}\n Effect: {item.TransitionAction}");
                                }
                            }
                            break;
                        }
                    case EA.ObjectType.otElement:
                        {
                            ele = Rep.GetContextObject();
                            packageNames.Add($"{ele.Type} : {ele.Name}");
                            foreach (EA.Connector item in ele.Connectors)
                            {
                                int clientId = item.ClientID;
                                int supplierId = item.SupplierID;
                                EA.Element clientElement = Rep.GetElementByID(clientId);
                                EA.Element supplierElement = Rep.GetElementByID(supplierId);

                                packageNames.Add($" From : {clientElement.Name}\n To: {supplierElement.Name}\n Trigger: {item.TransitionEvent}\n Effect: {item.TransitionAction}");
                            }
                            break;
                        }
                }

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: SOLVED:Retrieve All Elements On A Diagram
« Reply #18 on: December 15, 2020, 06:05:55 am »
Code: [Select]
foreach (EA.Element element in diag.DiagramObjects)This is where you are going wrong. There are no EA.Elements in the DiagramObjects collection, only EA.DiagramObjects (yes, sometimes it's that obvious, certainly not always though ;D)
Try
Code: [Select]
foreach (EA.DiagramObject diagramObject in diag.DiagramObjects)
Geert