How to known the kind of object

Started by rchevallier, February 03, 2023, 19:42:08 PM

Previous topic - Next topic

rchevallier

how to recognize in jArchi if a selected object is an element? a relationship?
Thx

Jean-Baptiste Sarrodie

Hi,

The straightforward answer is, check its type and see if it contains the string "relationship".

But another option is to filter the selection (which is a collection of only one object in this case) with either 'element' or 'relationship' and see if its lenght is zero or not:

if(selection.filter('element').size()) {
   console.log('Selection contains at least one element')
}
if(selection.filter('relationship').size()) {
   console.log('Selection contains at least one relationship')
}

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.

rchevallier

Thanks, so no magic  :'(
Then how to distinguish a visual Object (selection in a view) from a Concept (selection in the model tree) ?

Jean-Baptiste Sarrodie

Hi,

Quote from: rchevallier on February 04, 2023, 16:18:42 PMThen how to distinguish a visual Object (selection in a view) from a Concept (selection in the model tree) ?

if (selection.first().concept == selection.first()) {
  console.log('This is a concept')
} else {
  console.log('This is a visual object')
}

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.


Phil Beauvoir

Also this will tell you the class of the object:

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