Author Topic: Find all diagrams an Element is in.  (Read 1898 times)

Ruff

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Find all diagrams an Element is in.
« on: December 12, 2024, 02:00:15 am »
If an element is in a package, how can you script a way to located all the diagrams that it's contained in?

(I'm aware of Element.Diagrams and I'm not looking for sub-diagrams of the element, I'm talking across the repository.)

Would using the Element.Connectors.DiagramID be the answer or does the Connectors DiagramID hold another meaning?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13287
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Find all diagrams an Element is in.
« Reply #1 on: December 12, 2024, 02:19:09 am »
You use Repository.SQLQuery to get the ID's of all the diagrams that have a diagramObject with your elements ElementID.

Connector.DiagramID is basically only used by messages in sequence diagrams

Geert

Ruff

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Find all diagrams an Element is in.
« Reply #2 on: December 12, 2024, 03:08:08 am »
I found your previous post on the subject.

I was able to get working code:

Code: [Select]
const regex = /<Diagram_ID>(.*?)<\/Diagram_ID>/g;

function parseDiagramIDs(xmlString) { //XML Parsers were not working for me so I modified to use regex.
    // Define a regex pattern to match all <Diagram_ID> tags and capture their values
   
    const diagramIDs = [];
    let match;

    // Execute regex and push all matches to the array
    while ((match = regex.exec(xmlString)) !== null) {
        if (match[1]) {
            diagramIDs.push(match[1]); // Push the captured value (Diagram ID) to the array
        }
    }

    if (diagramIDs.length === 0) {
        throw new Error("No Diagram_IDs found in the XML.");
    }
   
    return diagramIDs.map( id => new Number(id));
}

 function iutils_GetDiagramOccurences(anObject) {
var num_diagrams;
var theObject As EA.Element;
theObject = anObject;

// Construct and execute the query
var sql = "";

sql += " select do.Diagram_ID "
     + " from t_diagramobjects do "
     + " where do.Object_ID = " + theObject.ElementID+ ";"

var queryResult = Repository.SQLQuery( sql );

var diagramIdsNum = [];
if ( queryResult.length > 0 )
{
//Session.Output(queryResult)
diagramIdsNum = parseDiagramIDs( queryResult );
}
return diagramIdsNum;
 }