Archi Forum

Discussion Boards => jArchi => Topic started by: DaveVint on October 30, 2019, 15:30:50 PM

Title: Access to nesting through JArchi
Post by: DaveVint on October 30, 2019, 15:30:50 PM
Hi,

I've been trying to create a JArchi script which clones the elements and diagrams from a 'template' model into the current model as a standard starting point for a new ABB. The ABB is modelled as a grouping (based on organisational guidelines). One diagram that is being copied is an overview of the ABB, showing the grouping with key elements  nested. Thus in the source diagram, moving the ABB grouping also moves the nested elements. When I'm trying to create the clone of the diagram, I can't figure out how to identify that the nested element is in fact nested, nor how to clone the nesting. I tried using the 'parent' property but it's always undefined.  The bounds of the nested element appear to be relative to the grouping, not the diagram so everything is also shifted towards the top left corner.

Apologies if this is obvious - I'm new to Javascript as well, so may have missed something simple!

Thanks for your efforts with this great tool - I've just signed up for the Patreon.

Cheers,

Dave
Title: Re: Access to nesting through JArchi
Post by: Phil Beauvoir on October 30, 2019, 15:48:37 PM
Hi Dave,

welcome to the forums and thanks for signing up to Patreon, I appreciate it.

the parent() function applies to a collection type. So let's say you select one nested object in a View and run this simple script:

var parents = selection.parent();

This returns a collection of parents and, in this case, containing one object. Had you selected more than one object, then parent() would return a collection of parents for each selected object.

So. knowing that we have selected only one object we can do this:

var parent = selection.parent().first();

Which will return the parent concept. And then you could do this:


var parent = selection.parent().first();
var bounds = parent.bounds;


Phil
Title: Re: Access to nesting through JArchi
Post by: Jean-Baptiste Sarrodie on October 30, 2019, 19:50:49 PM
Hi,

It seems that what you are trying to achieve is what I call "pattern based modelling". You should look at this wiki page (https://github.com/archimatetool/archi/wiki/Pattern-based-modelling-with-Archi) ;-)

Re scripting, once you get the visual object for the grouping, you have to get its children. This kind of navigation is done through a Collection, so if grouping is your Grouping, then you have children = $(grouping).children()

Once you have the collection of children, you can iterate on it:

grouping = ... // depends on the way you select your ABB
children = $(grouping).children();
children.each(function(child) {
  do_something_with(child);
})


Regards,

JB
Title: Re: Access to nesting through JArchi
Post by: DaveVint on October 31, 2019, 10:18:18 AM
Thanks for the responses both - useful info! I'll see how to incorporate this into my script.

One follow-on question if I may. The example script ('Create Views and Visual Objects')  includes creation of elements, visual diagram objects, a relationship and a note. I can't figure out how to create a 'connection' object between the note and a visual diagram object. The add( relationship, source, target) doesn't seem to work because there is no underlying ArchiMate relationship, it's purely visual.

Thanks!
Title: Re: Access to nesting through JArchi
Post by: Phil Beauvoir on October 31, 2019, 10:23:07 AM
Dave, did you create the relationship first? Can you post your code?
Title: Re: Access to nesting through JArchi
Post by: DaveVint on October 31, 2019, 10:34:31 AM
Hi Phil,

There is a no ArchiMate relationship - I'd just like to create a 'connection' between the note and diagram element. My own code is on a different machine without internet access, but the 'Create Views and Visual Objects.ajs' example JArchi script can be used as a basis. How would I create a 'connection' between the 'note' created on line 52 of that script and either of the visual objects created on lines 44 and 45? This is done through the GUI using the 'Connection' in the same palette section as the 'Note' and 'Group'.

Cheers,

Dave
Title: Re: Access to nesting through JArchi
Post by: Phil Beauvoir on October 31, 2019, 10:48:15 AM
Ah, got you. I didn't read "between the note and a visual diagram object" ;-)

Creating those types of non-ArchiMate connections hasn't been implemented in jArchi yet. I guess it's something to add to the list.
Title: Re: Access to nesting through JArchi
Post by: DaveVint on October 31, 2019, 10:52:29 AM
Thanks Phil!
Title: Re: Access to nesting through JArchi
Post by: DaveVint on October 31, 2019, 11:38:04 AM
Got the nesting working now. Thanks for your help. Once it's finished, I'll post the script.

Cheers,

Dave