1
Automation Interface, Add-Ins and Tools / Re: Get/check all stereotypes via SQL Query?
« on: June 13, 2025, 08:59:39 pm »
Geert, thank you! Works great, even if it adds some complexity.
Best regards,
Daniel
Best regards,
Daniel
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
SELECT
source.Name as 'Some Name'
FROM t_object source
LEFT JOIN t_connector link1 ON (link1.Start_Object_ID = source.Object_ID AND link1.Connector_Type = 'Aggregation')
LEFT JOIN t_object target ON (link1.End_Object_ID = target.Object_ID)
WHERE
target.Object_ID = 1097
<?xml version="1.0" encoding="UTF-8"?>
<EADATA>
<Dataset_0>
<Data>
<Row>
<Application>Sparx EA</Application>
<Vendor>SparxSystems</Vendor>
<Homepage>http://sparxsystems.com</Homepage>
</Row>
</Data>
</Dataset_0>
<Dataset_1>
<Data>
<Row>
<Application>Word</Application>
<Vendor>Microsoft</Vendor>
<Homepage>https://microsoft.com</Homepage>
</Row>
</Data>
</Dataset_1>
</EADATA>
Can I suggest Repository.CurrentSelection, which gives you more information about what is selected.
EASelection Class
It will tell you that the selection is on the diagram (selection.Location == "Diagram"), the element being displayed in all the properties windows, (selection.Context) and the full list of the elements in that selection. (selection.List)
Those are all properties that are available without additional database queries. You can use them in locations like building menus or update commands without negatively impacting performance. The final significant property for that object is the ElementSet, which will load all of the selected objects. It will be a faster way of accessing all of the selected objects than calling Repository.GetElementByID or Repository.GetElementByGuid for each item individually.
The problem with GetContexObject is that the object could be selected anywhere, including the browser, so I suggest you use this method to get the GUID (or ID) of the selected object, then use Diagram.SelectedObjects, iterate and select the matching object from GetContextObject (if no match then the object has been selected else where).
That should get you to the element (object) you are after
function OnDiagramScript()
{
var currentDiagram as EA.Diagram;
currentDiagram = Repository.GetCurrentDiagram();
if ( currentDiagram == null ) {
Session.Output("No diagram is selected. Done.");
return;
}
var selectedObjects as EA.Collection;
selectedObjects = currentDiagram.SelectedObjects;
if (selectedObjects.Count <= 0) {
Session.Output("No object is selected. Done.");
return;
}
if (selectedObjects.Count == 1) {
Session.Output("At least 2 objects MUST be selected. Done.");
return;
}
var primaryElement as EA.Element;
primaryElement = Repository.GetContextObject();
if (primaryElement == null) {
Session.Output("Could not find primary selection. Done.");
return;
}
for (var index = 0; index < selectedObjects.Count; index++)
{
var currentObject as EA.DiagramObject;
currentObject = selectedObjects.GetAt(index);
var currentElement as EA.Element;
currentElement = Repository.GetElementByID(currentObject.ElementID);
if (primaryElement.ElementID == currentElement.ElementID)
continue;
var link as EA.Connector;
if (linkDef.LinkDirection === undefined)
linkDef.LinkDirection = "ToPrimary";
if (linkDef.LinkDirection == "ToPrimary") {
link = LinkElementFromTo(currentElement, primaryElement, linkDef);
}
else {
link = LinkElementFromTo(primaryElement, currentElementElement, linkDef);
}
if (link == null) {
Session.Output("Failed to create link from '" + currentElement.Name + "' to '"+ primaryElement.Name +"'.");
}
}
Repository.ReloadDiagram(currentDiagram.DiagramID);
}
var linkDef = {
LinkName : "enhances",
LinkType : "Association",
LinkStereotype : "Application Function",
LinkDirection : "ToPrimary"
};
Repository.EnsureOutputVisible("Script");
OnDiagramScript(linkDef);
function LinkElementFromTo(sourceElement, targetElement, linkDef)
{
if (sourceElement == null) {
var msg = { Source : "LinkElementFromTo", Error : "Parameter @SourceElement is null." };
throw msg;
}
if (targetElement == null) {
var msg = { Source : "LinkElementFromTo", Error : "Parameter @TargetElement is null." };
throw msg;
}
if (linkDef == null) {
var msg = { Source : "LinkElementFromTo", Error : "Parameter @LinkDef is null." };
throw msg;
}
var source as EA.Element;
var target as EA.Element;
source = sourceElement;
target = targetElement;
//Session.Output("Source: " + source.Name + ", ID: " + source.ElementID);
//Session.Output("Target: " + target.Name + ", ID: " + target.ElementID);
var link as EA.Connector;
if (linkDef.LinkName === undefined)
linkDef.LinkName = "";
if (linkDef.LinkType === undefined)
linkDef.LinkType = "Association";
link = source.Connectors.AddNew(linkDef.LinkName, linkDef.LinkType);
if (link == null) {
var msg = { Source : "LinkElementFromTo::_Elements.AddNew", Error : "Failed to create link." };
throw msg;
}
if (linkDef.LinkStereotype !== undefined)
link.StereotypeEx = linkDef.LinkStereotype;
link.ClientID = source.ElementID;
link.SupplierID = target.ElementID;
link.Update();
source.Elements.Refresh();
target.Elements.Refresh();
return link;
}
SELECT element.ea_guid AS GUID
FROM ((t_object element
LEFT JOIN t_object port ON (port.ParentID = element.Object_ID))
LEFT JOIN t_objectproperties tag ON (tag.Object_ID = port.Object_ID))
WHERE <element filter criteria> AND <port filter criteria> AND tag.Property = '<TaggedValue-Name>'
SELECT other.ea_guid AS CLASSGUID, other.Name AS Name
FROM t_object other
WHERE <element filter criteria>
EXCEPT
SELECT element.ea_guid AS CLASSGUID, element.Name AS Name
FROM ((t_object element
LEFT JOIN t_object port ON (port.ParentID = element.Object_ID))
LEFT JOIN t_objectproperties tag ON (tag.Object_ID = port.Object_ID))
WHERE <element filter criteria> AND <port filter criteria> AND tag.Property = '<TaggedValue-Name>'
Excel and Access are no tools to do professional Architecture.We both agree on that. But as an consultant my job is to support the customer to improve. And even the environment is not optimal, it works. Could be better - for sure - but complaining is no solution. And even EA is far from optimal in many things necessary for scalable architectural work. But it's the best tool I know of, so I use it and do not complain about it's drawbacks. But I'm open for job offers, if you alluded to it.