Skip to content

Instantly share code, notes, and snippets.

@adgerrits
Last active February 23, 2020 10:51
Show Gist options
  • Save adgerrits/2390d4ef0560d26aac4350a533c0a3f6 to your computer and use it in GitHub Desktop.
Save adgerrits/2390d4ef0560d26aac4350a533c0a3f6 to your computer and use it in GitHub Desktop.
#jArchi script to merge two elements
/*
* Select 2 elements of the same type and merge the second one into the first one.
* Optional: delete the second one when it's not in use anymore.
* 2019, Ad Gerrits
*/
function q(text) {
return '"' + text + '"';
}
if (
selection.size() === 2 &&
$(selection.get(0)).is('element') &&
$(selection.get(1)).is('element') &&
$(selection.get(0)).type === $(selection.get(1)).type &&
typeof selection.get(0).view === 'undefined' &&
typeof selection.get(1).view === 'undefined'
) {
var e1 = selection.get(0);
var e2 = selection.get(1);
var response = window.confirm(
'Merge element ' + q(e2.name) + ' into element ' + q(e1.name) + ' ?'
);
if (response == true) {
e1.merge(e2);
window.alert(
q(e2.name) +
' is merged into ' +
q(e1.name) +
'. ' +
'\n\n' +
q(e2.name) +
' is not in use anymore.'
);
var response = window.confirm(
'Delete unused element ' + e2.name + ' ?'
);
if (response == true) {
e2.delete();
window.alert(q(e2.name) + ' is deleted.');
} else {
window.alert(q(e2.name) + ' is still there (but not in use).');
}
} else {
window.alert('Merge is cancelled.');
}
} else {
window.alert(
'First select two Archimate elements of the same type in the Models Tree. \nThe second one selected will be merged into the first one.'
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment