Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Ruff 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?
-
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
-
I found your previous post on the subject (https://sparxsystems.com/forums/smf/index.php/topic,46932.msg274246.html#msg274246).
I was able to get working code:
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;
}