Book a Demo

Author Topic: Find all Diagrams that an Element is in?  (Read 4686 times)

OrenBM

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Find all Diagrams that an Element is in?
« on: August 07, 2014, 09:58:16 am »
Hi all,

Apologies if I've missed a thread on this topic that's answered this question.  

I'm in the middle of a JScript, iterating through the Elements to work on and I'm trying to find out how to find all of the diagrams that the element occurs within.  There appears to be a UI option to do this, but I can't seem to find a sane way of doing this.

BTW, the version is 9.3

Any help appreciated.
« Last Edit: August 07, 2014, 11:06:07 am by OrenBM »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Find all Diagrams that an Element is in?
« Reply #1 on: August 07, 2014, 03:34:50 pm »
You'll have to use an SQL Query to find out.

Here's a code snippet from my EA addin Framework on github that does this.

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;
    }

Code for model.getDiagramByQuery:
Code: [Select]
   //returns a list of diagrams according to the given query.
    //the given query should return a list of diagram id's
    internal List<Diagram> getDiagramsByQuery(string sqlGetDiagrams)
    {
        // get the nodes with the name "Diagram_ID"
        XmlDocument xmlDiagramIDs = this.SQLQuery(sqlGetDiagrams);
        XmlNodeList diagramIDNodes =
              xmlDiagramIDs.SelectNodes(formatXPath("//Diagram_ID"));
        List<Diagram> diagrams = new List<Diagram>();
        foreach (XmlNode diagramIDNode in diagramIDNodes)
        {
            int diagramID;
            if (int.TryParse(diagramIDNode.InnerText, out diagramID))
            {
                Diagram diagram = this.getDiagramByID(diagramID);
                diagrams.Add(diagram);
            }
        }
        return diagrams;
    }
and finally the code for SQLQuery
Code: [Select]
   /// generic query operation on the model.
    /// Returns results in an xml format
    public XmlDocument SQLQuery(string sqlQuery)
    {
          sqlQuery = this.formatSQL(sqlQuery);
          XmlDocument results = new XmlDocument();
            results.LoadXml(this.wrappedModel.SQLQuery(sqlQuery));
            return results;
    }

Geert

OrenBM

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Find all Diagrams that an Element is in?
« Reply #2 on: August 08, 2014, 07:08:45 am »
Hi Geert,

Thanks for this... I'll give it a try...

Regards
OrenBM