Archi Forum

Archi Plug-ins => jArchi => Topic started by: René on February 26, 2021, 12:55:05 PM

Title: Finding the Root
Post by: René on February 26, 2021, 12:55:05 PM
I wanna write an export script to get all capabilities in an hierarchical order, set by composition relationship. For this I have to determine one (or maybe more) root objects.

A root object means: this one has no inRels for Composition Relationship.

I have no glue how to catch them best. A simple solution: Making an further element called "root" and combine the root(s) manually with Composition Relations.

But I'm sure there must be a better solution. I thought not() - but this function gave me every relation except the named one. Is there a better way to filter it?
Title: Re: Finding the Root
Post by: Phil Beauvoir on February 26, 2021, 13:00:35 PM
Hi, as with any jArchi adivce, the best thing to do is post part of the jArchi script that you have tried (just the relevant part).

Also, a simple numbered sequence of what you are trying to do - e.g "1. Iterate through all concepts 2. Find all concepts that match critieria x 3. etc"
Title: Re: Finding the Root
Post by: Jean-Baptiste Sarrodie on February 26, 2021, 19:29:24 PM
Hi,

You have to use the filter() function on a collection to check if there's no incoming composition relationships.

Here's a small example:


function isRoot(e) {
  return ! $(e).inRels('composition-relationship').size()
}

function doSomething(e) {
  console.log(e)
}

$('capability').filter(isRoot).each(doSomething)


Regards,

JB
Title: Re: Finding the Root
Post by: René on February 28, 2021, 18:56:50 PM
@JB: Thanks. That's perfect.