Skip to content

Instantly share code, notes, and snippets.

@jbsarrodie
Last active March 8, 2023 14:35
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbsarrodie/9bcab008be7f7e75b737e43bfab43048 to your computer and use it in GitHub Desktop.
Save jbsarrodie/9bcab008be7f7e75b737e43bfab43048 to your computer and use it in GitHub Desktop.
#jArchi script to add all possible relationships to a view
// Find DiagramComponents for a given element in a given view
var getDiagramComponents = function(v, e) {
return $(v).find("concept").filter(function(o) {
return o.concept.id == e.id;
});
}
// Checks if a view contains a visual connection from src and tgt visual objects
var contains = function(r, src, tgt) {
found = false;
$(r).objectRefs().each(function(o) {
if (o.source.id == src.id && o.target.id == tgt.id) {
found = true;
}
});
return found;;
}
// Iterate through selected views to add relationships which exist in the model but not in the view
$(selection).filter("archimate-diagram-model").each(function(v) {
$(v).find("element").each(function(e) {
$(e.concept).rels().each(function(r) {
getDiagramComponents(v,r.source).each(function(src) {
getDiagramComponents(v,r.target).each(function(tgt) {
if (! contains(r, src, tgt)) {
v.add(r, src, tgt);
}
});
});
});
});
});
@evlibra
Copy link

evlibra commented Aug 2, 2019

Getting and error:

Script Error at: javax.script.ScriptException, javax.script.ScriptException: TypeError: Cannot get property "id" of null in

When tried to use for view:
Screenshot_22
Screenshot_1

On other test view with just 1 relation it worked fine

@jbsarrodie
Copy link
Author

Hi,

This can happen if you have some notes or visual groups (ie. non ArchiMate concepts). I did fix this some time ago but have never updated this gist, this is now done (one of the first call to "find" now filter on concepts).

Does this fix your issue ?

@evlibra
Copy link

evlibra commented Aug 21, 2019

Works fine now. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment