Book a Demo

Author Topic: API method for "Find in all Diagrams"  (Read 4318 times)

gfranz

  • EA User
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
API method for "Find in all Diagrams"
« on: April 18, 2013, 12:22:26 am »
Hello,

So far I haven't found an API counterpart for the context menu function "Find in all Diagrams". Is there one? I can run a search, but maybe there's a easier way to do this.

Thanks
Guido

Konrad Wieland

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: API method for "Find in all Diagrams
« Reply #1 on: April 18, 2013, 12:38:15 am »
Via the API you can "easily" find out which diagram objects of an element are in which diagram.

Is this not a possibility for you? Or did I misunderstand your question?

Cheers
Konrad

« Last Edit: April 18, 2013, 12:43:10 am by konradw »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: API method for "Find in all Diagrams"
« Reply #2 on: April 18, 2013, 01:49:24 am »
There is no such direct function. But you can easily write a SQL search that produces the desired results.

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: API method for "Find in all Diagrams"
« Reply #3 on: April 18, 2013, 04:00:03 pm »
Guido,

What I do in those circumstances is write an SQL query that returns me the diagramID's and run that using Repository.SQLQuery()
You then need to use the resulting ID's in Repository.GetDiagramByID() to get hold of an instance of those diagram objects.
See https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework/blob/master/EAAddinFramework/EAWrappers/ElementWrapper.cs

Code: [Select]
   //returns a list of diagrams that somehow use this element.
    public override HashSet<T> getUsingDiagrams<T>()
    {
        string sqlGetDiagrams = @"select distinct d.Diagram_ID from t_DiagramObjects d
                                  where d.Object_ID = " + this.wrappedElement.ElementID;
        List<UML.Diagrams.Diagram> allDiagrams = this.model.getDiagramsByQuery(sqlGetDiagrams).Cast<UML.Diagrams.Diagram>().ToList(); ; ;
        HashSet<T> returnedDiagrams = new HashSet<T>();
        foreach (UML.Diagrams.Diagram diagram in allDiagrams)
        {
            if (diagram is T)
            {
                T typedDiagram = (T)diagram;
                if (!returnedDiagrams.Contains(typedDiagram))
                {
                    returnedDiagrams.Add(typedDiagram);
                }
            }
        }
        return returnedDiagrams;
    }

Geert

gfranz

  • EA User
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Re: API method for "Find in all Diagrams"
« Reply #4 on: April 18, 2013, 04:03:27 pm »
Thanks a lot, I appreciate your help!