Access to nesting through JArchi

Started by DaveVint, October 30, 2019, 15:30:50 PM

Previous topic - Next topic

DaveVint

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

Phil Beauvoir

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
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Jean-Baptiste Sarrodie

Hi,

It seems that what you are trying to achieve is what I call "pattern based modelling". You should look at this wiki page ;-)

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
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

DaveVint

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!

Phil Beauvoir

Dave, did you create the relationship first? Can you post your code?
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

DaveVint

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

Phil Beauvoir

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.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

DaveVint


DaveVint

Got the nesting working now. Thanks for your help. Once it's finished, I'll post the script.

Cheers,

Dave