Author Topic: DiagramLinks and DiagramLink  (Read 1425 times)

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1137
  • Karma: +30/-8
    • View Profile
DiagramLinks and DiagramLink
« on: April 23, 2025, 02:29:38 am »
Before I post anything else, according to
https://sparxsystems.com/enterprise_architect_user_guide/17.0/add-ins___scripting/diagram2.html for v17,
https://sparxsystems.com/enterprise_architect_user_guide/16.1/add-ins___scripting/diagram2.html for v16.1,
https://sparxsystems.com/enterprise_architect_user_guide/16.1/add-ins___scripting/diagramlinks.html, and
https://sparxsystems.com/enterprise_architect_user_guide/17.0/add-ins___scripting/diagramlinks.html

DiagramLinks is - A list of DiagramLink objects, each containing information about the display characteristics of a connector in a diagram.

and

And a DiagramLink is an object that holds display information on a connector between two elements in a specific diagram. It includes, for example, the custom points and display appearance. It can be accessed from the Diagram DiagramLinks collection.

Can somebody clarify if the documentation is correct?

I have a JavaScript returning a DiagramLinks.Count way higher than the actual number of connectors in the diagram.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: DiagramLinks and DiagramLink
« Reply #1 on: April 23, 2025, 04:13:02 pm »
Yes, the documentation appears correct.

DiagramLinks includes the hidden connectors on the diagram, so that might be the reason why you are seeing more diagramLinks than you see connectors on the diagram.

Geert

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1137
  • Karma: +30/-8
    • View Profile
Re: DiagramLinks and DiagramLink
« Reply #2 on: April 23, 2025, 04:46:21 pm »
Thank you Geert. I’m relatively sure this isn’t cause by hidden connectors but with Sparx EA in the mix I could be wrong. The script is intended to hide certain connectors -i.e., associations. The diagram is essentially a visually nested decomposition using ArchiMate objects linked with aggregations or compositions and has these relationships automatically hidden by Sparx EA.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: DiagramLinks and DiagramLink
« Reply #3 on: April 23, 2025, 05:24:01 pm »
Thank you Geert. I’m relatively sure this isn’t cause by hidden connectors but with Sparx EA in the mix I could be wrong. The script is intended to hide certain connectors -i.e., associations. The diagram is essentially a visually nested decomposition using ArchiMate objects linked with aggregations or compositions and has these relationships automatically hidden by Sparx EA.
So did you investigate where these diagramslinks come from?
Each diagramlink has a connectorID.

You can also check if the diagramlinks in the database correspond to those in the DiagramLinks Collection.

If you see weird results, it might be worth to run a project integrity check.

Geert

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1137
  • Karma: +30/-8
    • View Profile
Re: DiagramLinks and DiagramLink
« Reply #4 on: April 23, 2025, 05:47:27 pm »
I have not yet completed my investigation but will report the results here. The counts look more like the total number of connectors for all elements in the diagram irrespective of whether they are supposed to be present in the diagram or not, plus some connector types are not present in the diagram at all - e.g., NoteLink.

I'll post the results of a complete investigation here.

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1137
  • Karma: +30/-8
    • View Profile
Re: DiagramLinks and DiagramLink
« Reply #5 on: April 23, 2025, 07:40:42 pm »
I have run some checks and and DiagramLinks does not always contain an entry/row per connector in the diagram, it only contains the right counts for new diagrams. Furthermore, the only common theme I can think off is the some of diagrams with the wrong counts are modified copies of other diagrams. This could be an integrity issue, I have not run an integrity check but, if it is, the data integrity of the repository will be heavily comprised as I can see connectors in DiagramLinks and t_diagramlinks with start and end objects that do not visually appear in diagrams.

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1137
  • Karma: +30/-8
    • View Profile
Re: DiagramLinks and DiagramLink
« Reply #6 on: April 23, 2025, 08:29:05 pm »
Further update, if the query below is correct we have about 15% - i.e., about 2,400 - of the links in t_diagramlinks, with a start or end object not in the current diagram, and a integrity check does not find them and correct them.

Is there a way to fix this?

Code: [Select]
select dlinks.DiagramID, ConnectorID, Start_Object_ID LinkedObjectID
from t_diagramlinks dlinks
inner join t_connector conn
on dlinks.ConnectorID = conn.Connector_ID
inner join t_object sobj
on conn.Connector_ID = sobj.Object_ID
inner join t_object eobj
on conn.Connector_ID = eobj.Object_ID
where Start_Object_ID NOT IN(
SELECT Object_ID FROM t_diagramobjects dObjs
WHERE dObjs.Diagram_ID = dlinks.DiagramID)
union
select dlinks.DiagramID, ConnectorID, End_Object_ID LinkedObjectID
from t_diagramlinks dlinks
inner join t_connector conn
on dlinks.ConnectorID = conn.Connector_ID
inner join t_object sobj
on conn.Connector_ID = sobj.Object_ID
inner join t_object eobj
on conn.Connector_ID = eobj.Object_ID
where End_Object_ID NOT IN(
SELECT Object_ID FROM t_diagramobjects dObjs
WHERE dObjs.Diagram_ID = dlinks.DiagramID)

Query is a SQL Server query

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: DiagramLinks and DiagramLink
« Reply #7 on: April 23, 2025, 08:51:59 pm »
I think the diagramslinks are only updated if a diagram is loaded.

Loading (or updating?) the diagrams in question should resolve the problem.

For comparison, your query resulted in 40 records in my model (on a total of 6812 diagramlinks)

Normally these should not pose a problem, and I would expect the EA.Diagram.DiagramLinks collection to be correct (and not inlcude these stale records)

Geert

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1137
  • Karma: +30/-8
    • View Profile
Re: DiagramLinks and DiagramLink
« Reply #8 on: April 23, 2025, 09:34:03 pm »
Thank you Geert, loading or updating the diagram, the later using a script, does not correct the issue.

[SNIP]
Normally these should not pose a problem, and I would expect the EA.Diagram.DiagramLinks collection to be correct (and not inlcude these stale records)
There are a problem only insofar as Sparx EA does not have an elegant way of filtering the connectors displayed in a diagram - e.g., I do not want to display associations on a decomposition diagram that uses aggregations or compositions because it messes the diagram. I was hoping to use a script to hide certain connectors instead of having to do it manually.

I really whish Sparx Systems introduce a feature to elegantly hide certain types of connectors for each diagram. I think this has been articulated a number of times in this forum. And I know it is a user forum, but I may made an enhancement request and have lost track of it, primarily because there is not easy way to track them.

I totally agree DiagramLinks should not include stale records.


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: DiagramLinks and DiagramLink
« Reply #9 on: April 23, 2025, 09:51:34 pm »
In the past I remember writing a script to hide certain connectors.

Should not be too difficult.

- loop diagram links
- get connector object
- if connector.Type = "Association" then
-   diagramLink.IsHidden = true
-   diagramLink.Update()

Geert

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1137
  • Karma: +30/-8
    • View Profile
Re: DiagramLinks and DiagramLink
« Reply #10 on: April 23, 2025, 10:44:47 pm »
The script is easy, it is exactly as you described it. But it does not perform very well, it takes ages to execute. In fact, it is only because it took ages to execute that I started looking into counts.
« Last Edit: April 23, 2025, 10:57:26 pm by Modesto Vega »

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1137
  • Karma: +30/-8
    • View Profile
Re: DiagramLinks and DiagramLink
« Reply #11 on: April 23, 2025, 11:17:38 pm »
This is the script, it takes 1 minute and 30 seconds to execute on a single diagram!!! And visually does nothing unless I manually reload  the diagram. In comparison, using Layout/Appearance/Set Visible Relations takes much sorter.

Unless there is an obvious way to optimise it, writing and using it is a complete waste of time.

Even if we were to implement a script like that at package level, instead of diagram level, it will be too slow. It may work - i.e., worth executing - if we were to run it for the whole repo on a schedule overnight and AFIK this is not possible.

Code: [Select]
!INC Local Scripts.EAConstants-JavaScript

/*
 * This code has been included from the default Diagram Script template.
 * If you wish to modify this template, it is located in the Config\Script Templates
 * directory of your EA install path.
 *
 * Script Name:
 * Author:
 * Purpose:
 * Date:
 */

/*
 * Diagram Script main function
 */
function OnDiagramScript()
{
// Get a reference to the current diagram
var currentDiagram as EA.Diagram;
currentDiagram = Repository.GetCurrentDiagram();

if ( currentDiagram != null )
{
// Get a reference to any selected connector/objects
var selectedConnector as EA.Connector;
var selectedObjects as EA.Collection;
selectedConnector = currentDiagram.SelectedConnector;
selectedObjects = currentDiagram.SelectedObjects;

if ( selectedConnector != null )
{
// A connector is selected
}
else if ( selectedObjects.Count > 0 )
{
// One or more diagram objects are selected
}
else
{
// Nothing is selected
var linkCount = 0;

while (linkCount < currentDiagram.DiagramLinks.Count)
{
var diagramConnector as EA.Connector;
var diagramLink as EA.DiagramLink;

diagramLink = currentDiagram.DiagramLinks.GetAt(linkCount);

if (diagramLink.ObjectType = otConnector)
{
diagramConnector = Repository.GetConnectorByID(diagramLink.ConnectorID);

if (diagramConnector.Type = 'Association')
{
diagramLink.IsHidden = 1;
diagramLink.Update();
}
}
linkCount = linkCount + 1;
}
currentDiagram.Update();
Session.Prompt("Updated", promptOK);
}
}
else
{
Session.Prompt( "This script requires a diagram to be visible.", promptOK)
}

}

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: DiagramLinks and DiagramLink
« Reply #12 on: April 24, 2025, 01:36:46 am »
A serious improvement might be to first get all the connector ID's of the connectors you want to hide.
If you put them in a dictionary you can then loop the diagramlinks, and check if the ID is in the dictionary.

This avoids having to instantiate connector objects only to figure out if it is an association and set the hidden property.

I don't think you need the currentDiagram.Update either, but you might want to do a Repository.ReloadDiagram if you hid one or more connectors.

Pretty sure that should improve performance drastically.

Geert