Is it possible to get the absolute position of a visual connection in a view ?

Started by jsimoncello, March 10, 2023, 16:41:38 PM

Previous topic - Next topic


I am trying to auto-number the relations shown in a view starting from top and then left to right.
Problem is I haven't found any reliable way to get start or end or text position for a connection (except if this relation has bendpoints).
Is there any way to do it with the SDK ?

Jean-Baptiste Sarrodie


As the anchor points (exact place where a connection connects to an object) are dynamically computed based on the chosen rendering algorithm and some other factors, it is not possible to get them through jArchi API.


If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.



just in case, a very basic version using centers of source and target element of the flow. I thing it can be refined by taking bendpoints into account.

var archimateView = $(selection).first();
if (archimateView.type != "archimate-diagram-model") {
    window.alert("Please select a view before running this script");

} else {
    let flowsInView = [];
    $(archimateView).children("flow-relationship").each(function (f) {
        let srcCoord = getElementCenter(f.source);
        let tgtCoord = getElementCenter(;
        let x = (srcCoord.x + tgtCoord.x) / 2;
        let y = (srcCoord.y + tgtCoord.y) / 2;
        flowsInView.push([x, y, f]);

    flowsInView.sort(([a, b, c], [d, e, f]) => b - e || a - d);
    for (let i = 0; i < flowsInView.length; i++) {
        let flow = flowsInView[i][2];
        let newFlowName = "" + (i + 1);
        flow.labelExpression = "F" + newFlowName.padStart(3, "0") + " " +[0-9a-z]*/gm, "");
//get the center of the visual element from the origin of the view (top left)
function getElementCenter(el) {
    let absCoord = getAbsoluteCoord(el);
    return { x: absCoord.x + (absCoord.width) / 2, y: absCoord.y + absCoord.height / 2, }

 *  compute x,y of the element starting from the origin of the view (element.bounds returns x,y from the parent element not from the view)
 * @param el
function getAbsoluteCoord(el) {
    let result = el.bounds;

    $(el).parents().each(function (pa) {
        if (pa.bounds !== null && pa.bounds !== undefined) {
            result.x += pa.bounds.x
            result.y += pa.bounds.y
    return result;